Skip to content

replace string with regular expression got wrong output #5132

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

Closed
atoms18 opened this issue Sep 12, 2023 · 2 comments · Fixed by #5167
Closed

replace string with regular expression got wrong output #5132

atoms18 opened this issue Sep 12, 2023 · 2 comments · Fixed by #5167
Labels
bug Something isn't working bundler Something to do with the bundler

Comments

@atoms18
Copy link

atoms18 commented Sep 12, 2023

What version of Bun is running?

1.0.1+31aec4ebe325982fc0ef27498984b0ad9969162b

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

when try to match a regular expression with these emoji and replace it with string

let str = "🔴11 54 / 10,000";
str = str.replace(/[🔵🔴,]+/g, '');
console.log(str);

What is the expected behavior?

the outputs should be:
11 54 / 10000
instead of
🔴 / 0000

What do you see instead?

No response

Additional information

No response

@atoms18 atoms18 added the bug Something isn't working label Sep 12, 2023
@Electroid Electroid added the bundler Something to do with the bundler label Sep 12, 2023
@Electroid
Copy link
Contributor

@dylan-conway Any ideas here?

@dylan-conway
Copy link
Member

This is the transpiled source:

let str = "\uD83D\uDD3411 54 / 10,000";
str = str.replace(/[\u{1f535}\u{1f534},]+/g, "");
console.log(str);

Using the regex constructor with a string works, new RegExp("[🔵🔴,]+", "g");, so we probably aren't encoding /.../ correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants