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

Bun does not provide last matched string when using RegExp["$&"] #17978

Open
kevgeoleo opened this issue Mar 7, 2025 · 2 comments
Open

Bun does not provide last matched string when using RegExp["$&"] #17978

kevgeoleo opened this issue Mar 7, 2025 · 2 comments
Labels
bug Something isn't working confirmed bug We can reproduce this issue jsc Something related to JavaScriptCore regression

Comments

@kevgeoleo
Copy link

What version of Bun is running?

1.2.4+fd9a5ea66

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

Hi,
I would like to report an issue I encountered in Bun while I was running the following code snippet:

var input = "foo bar baz";
var re_g = new RegExp("bar", "g");
input.match(re_g);
console.log(RegExp["$&"]);  // Node and Deno: bar, Bun: no output

What is the expected behavior?

bar

What do you see instead?

no output

Additional information

No response

@kevgeoleo kevgeoleo added bug Something isn't working needs triage labels Mar 7, 2025
@RiskyMH RiskyMH added node.js Compatibility with Node.js APIs confirmed bug We can reproduce this issue regression and removed needs triage labels Mar 7, 2025
@RiskyMH
Copy link
Member

RiskyMH commented Mar 7, 2025

regressed in bun v1.1.34, likely JSC change


Also, when I put bar into a group then it works as expected, so appears to only work if there are brackets in regex

"foo bar baz".match(/bar/g);
console.log([RegExp["$&"]]);  // Node: bar, Bun: <empty str>

"foo bar baz".match(/ba(r)/g);
console.log([RegExp["$&"]]);  // Node & Bun: bar

@RiskyMH RiskyMH added jsc Something related to JavaScriptCore and removed node.js Compatibility with Node.js APIs labels Mar 7, 2025
@RiskyMH
Copy link
Member

RiskyMH commented Mar 7, 2025

I made a report to webkit with your repo: https://bugs.webkit.org/show_bug.cgi?id=289337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue jsc Something related to JavaScriptCore regression
Projects
None yet
Development

No branches or pull requests

2 participants