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

Unicode Properties are not supported/broken for Regular Expressions (Regex) #29807

Closed
kfiri opened this issue Aug 29, 2020 · 10 comments
Closed
Labels
DX Issues concerning how the developer experience can be improved. Platform: Android Android applications. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon. Tech: Hermes Hermes Engine: https://hermesengine.dev/

Comments

@kfiri
Copy link

kfiri commented Aug 29, 2020

Description

The Unicode Properties feature for regular expression is supported for Node, Swift and Java (see References bellow).
However, when I use that feature in my code, it returns a wrong answer (specifically I used \p{L} and the test method).
For example, /\p{L}/u.test('a') returns false.

References

JS - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes
Swift - https://developer.apple.com/documentation/foundation/nsregularexpression
Java - https://docs.oracle.com/javase/tutorial/essential/regex/unicode.html

React Native version:

System:
    OS: Windows 10 10.0.19041
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 3.49 GB / 15.90 GB
  Binaries:
    Node: 14.5.0 - C:\Program Files\nodejs\node.EXE     
    Yarn: Not Found
    npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.1
      System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Version  4.0.0.0 AI-193.6911.18.40.6626763
  Languages:
    Java: 1.8.0_211
    Python: 2.7.18
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.2 => 0.63.2
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. run the code
console.log(/\p{L}/u.test('a'));
console.log(/\p{L}/u.test('ש'));

anywhere in your app component.

Expected Results

/\p{L}/u.test('a') and /\p{L}/u.test('ש') should return true (they have the unicode property "Letter").
they both return false.

Snack, code example, screenshot, or link to a repository:

import React from 'react';
import { View, Text } from 'react-native';

function App() {
  console.log(/\p{L}/u.test('a'));
  console.log(/\p{L}/u.test('ש'));
  return (
    <View>
      <Text>App</Text>
    </View>
  );
}

export default App;

image

@safaiyeh safaiyeh added DX Issues concerning how the developer experience can be improved. Platform: Android Android applications. Platform: iOS iOS applications. and removed Needs: Triage 🔍 labels Aug 31, 2020
@kfiri
Copy link
Author

kfiri commented Sep 24, 2020

Hya, is there anything new with this issue? for now, I just use English characters which is not very good for my project in the long run

@conradlo
Copy link

I had the same issue recently.
Out team's solution is to use the @babel/plugin-proposal-unicode-property-regex plugin to transpile the unicode regex.

@odyodyodys
Copy link

Any clues on what can cause this? On multiple environment it only occurs on one and we yet to figure out the reason.

@arnaudambro
Copy link

I had the same issue recently.
Out team's solution is to use the @babel/plugin-proposal-unicode-property-regex plugin to transpile the unicode regex.

it doesn't do anything for me, is there an extra step to do ?

[EDIT]

I forgot to update my babel config in babel.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['@babel/plugin-proposal-unicode-property-regex'],
};

@Bardiamist
Copy link
Contributor

Bardiamist commented Nov 10, 2022

Can somebody confirm that it works properly on not properly 🙂
facebook/hermes#850
I see the folder node_modules/@babel/plugin-proposal-unicode-property-regex but how to understand that my project uses it?

@cortinico cortinico added the Tech: Hermes Hermes Engine: https://hermesengine.dev/ label Nov 25, 2022
@nazmeln
Copy link

nazmeln commented Mar 27, 2023

Hey, @cortinico @conradlo @odyodyodys @safaiyeh @Bardiamist
After upgrading the RN version to 0.71.4 as well as babel dependencies, the plugin stopped working and there was a TypeScript error in one of my validation files:

TypeError: /pathToFile/validations.ts: symbol.charCodeAt is not a function
    at symbolToCodePoint

I used this xregexp library to support Unicode Properties functionality.
❗️Please note that it has specific syntax with backslashes

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 24, 2023
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Oct 1, 2023
@uladzislau-stuk
Copy link

I can confirm that "Unicode Properties are not supported/broken for Regular Expressions (Regex)" are not supported when Hermes is enabled

@uladzislau-stuk
Copy link

uladzislau-stuk commented Jan 17, 2024

🎬 I am getting back with an update. I tried to use xregexp and it started working, but I debugged it and didn't see anything why I needed to use this library.

  1. My initial regular expression was
    new RegExp(/^[\p{Script=Han}\s]+$/, 'u')

  2. I installed xregexp and used regexp such way
    XRegExp('^\p{Han}+$');

  3. After debugging XRegExp I brushed up initial regexp
    new RegExp(/^[\p{Script=Han}\s]+$/u)

✅ I successfully built the project and error with "Invalid dialect ..." disappeared, that's it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Issues concerning how the developer experience can be improved. Platform: Android Android applications. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon. Tech: Hermes Hermes Engine: https://hermesengine.dev/
Projects
None yet
Development

No branches or pull requests

9 participants