String ordering produce wrong results when called from webassembly. #4034
#14,895 创建于 2021年8月18日
仓库指标
- Star
- (27,361 star)
- PR 合并指标
- (平均合并 19天 10小时) (30 天内合并 147 个 PR)
描述
We noticed that the results of using the compare function in the std::collate is different when called using webassembly than when called using C++ native.
The main bug, was that in webassembly, it add the strings which begin with capital letter to a different category, and sort it at the beginning of the list, while this is not the case in the C++ native code. Other bug, was that the strings begin with German ümlaut characters, are also added to different category than the normal English characters, which also not the case in C++ native code. For example, when sorting using the C++ native, the 'a' should be treated like 'ä'.
Attached is screenshots of the difference between the sorting using C++ native code, and the sorting when called using webassembly.
Sorting using native code results:
Sorting using webassembly:

We implemented a reproducer code using C++, which compare different strings, and found that when we use the same code with the same locales in the webassembly, different comparison output result.
The idea of the reproducers is to show the difference between C++ native and webassembly in comparing strings with different locales, using the same code.
You can do the following steps to execute the reproducer
1- Extract the zip folder.
2-Execute the bash script by using (sh reproduce.sh)
3- Enter 1 if you want to run the webassembly code.
4- Enter 0 if you want to run the C++ Native code.
Follow these steps, in order to show these results in webassembly:
Click on compare button to show the comparison of the previously mentioned strings. Click on the button related to each locale, in order to sort the strings according to this locale. Click on the transform button related to each locale, in order to sort these strings according to this locale, but after transforming the strings to lower case. to reproduce the previously discussed bugs.
In our reproducers we compared the following pairs of strings:
Anton, anton
anton, Barbara
Anton, Barbara
Anton, barbara
barbara, Barbara
with the following locales:
Empty Locale. C Locale. English Locale. German Locale.
From the previous results, it was obvious that there were difference between the results of the C++ Native and webassembly.