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
armadillojim opened this Issue Jun 13, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@armadillojim
Copy link

armadillojim commented Jun 13, 2018

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
@TheSavior

This comment has been minimized.

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

This comment has been minimized.

Copy link
Author

armadillojim commented Jun 14, 2018

@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

This comment has been minimized.

Copy link
Author

armadillojim commented Jun 14, 2018

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

This comment has been minimized.

Copy link
Member

TheSavior commented Jun 15, 2018

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

#19737

@armadillojim

This comment has been minimized.

Copy link
Author

armadillojim commented Jun 16, 2018

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)?

@MrPluto

This comment has been minimized.

Copy link

MrPluto commented Sep 6, 2018

seem like startswith cant work well if a str contain Chinese

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment