question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

string `startsWith` produces false negatives

See original GitHub issue

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:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
armadillojimcommented, Apr 9, 2019

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

0reactions
arthakdoocommented, 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found