string `startsWith` produces false negatives
See original GitHub issue- Review the documentation: https://facebook.github.io/react-native
- Search for existing issues: https://github.com/facebook/react-native/issues
- Use the latest React Native version: https://github.com/facebook/react-native/releases
- Run
react-native info
in your terminal and paste its contents under “Environment” - Let us know how to reproduce the issue. Include a code sample, share a project, or share an app that reproduces the issue using https://snack.expo.io/
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
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How to use `string.startsWith()` method ignoring the case?
This answer is not true because toLowerCase() uses Locale.getDefault() internally to change the chars and that might lead to false negatives. Let's say...
Read more >String startsWith() Method in JavaScript - DEV Community
This hit me when you tested to see if negative indexes worked. I find that writing test cases makes learning new programming languages...
Read more >String.StartsWith Method (Java.Lang) - Microsoft Learn
The result is false if toffset is negative or greater than the length of this String object; otherwise the result is the same...
Read more >Practices of Science: False Positives and False Negatives
All tests have a chance of resulting in false positive and false negative errors. They are an unavoidable problem in scientific testing. This...
Read more >tf.keras.metrics.FalseNegatives | TensorFlow v2.11.0
If sample_weight is given, calculates the sum of the weights of false negatives. This metric creates one local variable, accumulator that is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 https://github.com/facebook/react-native/issues/19737#issuecomment-454205028
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.
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