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

Numerous incorrect regex results #130

Open
sgbeal opened this issue Mar 1, 2020 · 6 comments
Open

Numerous incorrect regex results #130

sgbeal opened this issue Mar 1, 2020 · 6 comments

Comments

@sgbeal
Copy link

sgbeal commented Mar 1, 2020

In Firefox and Chrome:

'abc'.split(/./)
Array(4) [ "", "", "", "" ]

In mujs (current version as of about an hour ago):

'abc'.split(/./)
["a", "c"]
@sgbeal
Copy link
Author

sgbeal commented Mar 1, 2020

Possibly related:

Chrome/FF:

'abc'.split(/^a/)
Array [ "", "bc" ]

mujs:

'abc'.split(/^a/)
["abc"]

@sgbeal sgbeal changed the title Incorrect regex result for "abc".split(/./) Incorrect regex result for "abc".split(/./) and split(/^a/) Mar 1, 2020
@sgbeal
Copy link
Author

sgbeal commented Mar 1, 2020

Here's another:

Chrome/FF:

' ; a;  b ; c'.split(/ *; */);
Array(4) [ "", "a", "b", "c" ]

mujs:

' ; a;  b ; c'.split(/ *; */)
[" ", "a", "b", "c"]

Note that space in the first array entry.

@sgbeal sgbeal changed the title Incorrect regex result for "abc".split(/./) and split(/^a/) Numerous incorrect regex results Mar 1, 2020
@sgbeal
Copy link
Author

sgbeal commented Mar 1, 2020

Another one:

Chrome/FF:

"aaaa bbb caaa".split(/a(a+)/)
Array(5) [ "", "aaa", " bbb c", "aa", "" ]

mujs:

"aaaa bbb caaa".split(/a(a+)/)
["a", "aa", " bbb c", "aa", ""]

@sgbeal
Copy link
Author

sgbeal commented Mar 1, 2020

Another couple:

Browsers:

"äbä".split(/ä/)
Array(3) [ "", "b", "" ] (EDIT: i initially pasted the wrong result there)
"bäb".split(/b/)
Array(3) [ "", "ä", "" ]

mujs:

"äbä".split(/ä/)
["\u00E4b", ""]
"bäb".split(/b/)
["b\u00E4", ""]

But "äbä".split(/b/) works.

(FWIW, i'm not actively searching for these, just stumbling across them while testing my own code, which uses regexp.c from this project.)

@Kagami
Copy link

Kagami commented Jan 25, 2024

It's still an issue with the latest commit, even simplest split regexp doesn't work:

% node -e 'console.log("test".split(/./))'
[ '', '', '', '', '' ]
% mujs
> "test".split(/./)
["t", "s", ""]

ccxvii added a commit that referenced this issue Jan 26, 2024
The "empty string at end of last match" should only trigger if the match
is empty!
@Kagami
Copy link

Kagami commented Jan 30, 2024

Fixed in 40556b3
Thanks @ccxvii.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants