Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string startsWith produces false negatives #19699

Closed
5 tasks done
armadillojim opened this issue Jun 13, 2018 · 8 comments
Closed
5 tasks done

string startsWith produces false negatives #19699

armadillojim opened this issue Jun 13, 2018 · 8 comments
Labels
Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.

Comments

@armadillojim
Copy link

Environment

Environment:
  OS: Linux 4.9
  Node: 8.11.2
  Yarn: 1.6.0
  npm: 5.6.0
  Watchman: Not Found
  Xcode: N/A
  Android Studio: Not Found

Packages: (wanted => installed)
  react: 16.3.1 => 16.3.1
  react-native: ~0.55.2 => 0.55.4

Description

I have a component that was filtering a list of suggestions, and I stumbled on a strange bug. The list was mysteriously not including some items it should have, and I eventually figured out that the Javascript engine was producing incorrect results on strings that had UTF8 characters in them. That is, someString.startsWith(someOtherString) was producing false when it shouldn't have.

Steps to Reproduce

console.log('mother'.startsWith('m'));
console.log('mother\'s'.startsWith('m'));
console.log('mother’s'.startsWith('m'));

Note the Unicode apostrophe in the last case.

If it makes a difference, I used create-react-native-app to bootstrap my app, and I'm running it in Expo.

Expected Behavior

true
true
true

Actual Behavior

true
true
false
@react-native-bot react-native-bot added the Platform: Linux Building on Linux. label Jun 13, 2018
@TheSavior
Copy link
Member

TheSavior commented Jun 13, 2018

I get true for all three use cases:

screen shot 2018-06-13 at 3 43 09 pm

Does this repro with 0.56.0?

@armadillojim
Copy link
Author

@TheSavior Thanks for the suggestion. However, I don't see any difference in the version of JavaScriptCore between 0.55 and 0.56. Both https://github.com/facebook/react-native/blob/0.55-stable/ReactAndroid/build.gradle and https://github.com/facebook/react-native/blob/0.56-stable/ReactAndroid/build.gradle use WebKit/webkit/38b15a3ba3c1b0798f2036f7cea36ffdc096202e.

Are you using react-native in development mode? I ask because I see in the documentation that that uses V8 instead of JavaScriptCore. I also tried this in Chrome's JavaScript console (which uses V8), and got the expected result (3 trues). Or am I confused about that? I'm using create-react-native-app and expo, and I'm testing on an Android device (and not a simulator).

@armadillojim
Copy link
Author

https://github.com/WebKit/webkit/tree/38b15a3ba3c1b0798f2036f7cea36ffdc096202e is from October 13, 2014. It's entirely possible there was a bug in WebKit that has been fixed sometime in the past three years. I was able just now to test in Safari, and Safari's JavaScript console produces the correct result.

@TheSavior
Copy link
Member

Ah, yeah, this sounds like a bug in JSC.

#19737

@armadillojim
Copy link
Author

Ok, thanks!

Yeah I saw that JavaScriptCore hasn't been updated since the beginning of react-native. That'll be a bear to upgrade carefully. D'oh. Oh well.

Maybe it'd be worth noting in the "JavaScript Environment" documentation page which version is in use (and its release date)?

@pppluto
Copy link

pppluto commented Sep 6, 2018

seem like startswith cant work well if a str contain Chinese

@arthakdoo
Copy link

arthakdoo commented Mar 12, 2019

const text = 'abcde 😎';   // note the emoji

text.startsWith('abc'); // <-- returns false (incorrect)
text.indexOf('abc'); // <-- returns zero (correct)

Node: 8.12.0
React: 16.8.2
React Native: 0.57.8
@babel/core: 7.3.3
@babel/preset-env: 7.3.1
@babel/preset-react: 7.0.0
Platform: Android

@armadillojim
Copy link
Author

@MrPluto and @dmaksimovic, React Native 0.56, 0.57, and 0.58 all continued to use the same JSC. They finally updated it, though. See #19737 (comment)

I double checked, and you can see the change live now in 0.59. https://github.com/facebook/react-native/blob/0.58-stable/ReactAndroid/build.gradle#L148 shows the old JSC, and https://github.com/facebook/react-native/blob/0.59-stable/ReactAndroid/build.gradle#L136 is now evergreen.

I haven't tried upgrading yet myself, but it seems that should fix this issue.

@facebook facebook locked as resolved and limited conversation to collaborators Jun 16, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Linux Building on Linux. Resolution: Locked This issue was locked by the bot.
5 participants