You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When giving StringScanner#scan a multiline (//m) regexp, instead of scanning just the next character, it scans characters after a newline too.
In Ruby, multiline modifier changes semantics of . to mean "any character", not "any character except \n".
In JavaScript instead, it changes semantics of ^ and $ to how they work in Ruby even without //m, so they match beginning/ending either of string or line. Except... there's no \A or \z.
Opal's StringScanner#scan implementation adds ^ to the beginning of the supplied regexp and copies the flags.
All combined cause a hard-to-discover bug. I don't have simple solutions for that issue, maybe except of using lookbehind to simulate \A in Opal's clone of StringScanner, but that only recently has been implemented in Safari.
Yes @takaram, I was also mistaken about this in the first version of the post. Later I edited it to clarify. But I wasn't aware of the JS s flag. #2610 fixes this issue by transpiling the regexps (but still needs some work due to performance impact). As of now, . is transpiled to [\s\S] if m flag is present. I foresee an issue with things like Regexp.union if we chose to depend on the flags.
This patch cherry-picks updated version of opal/opal#2610. This
update cleaned up Opal's regexp implementation quite a lot to fixopal/opal#2616 which in turn caused that we got 2 more tests passed
on Plurimath and only the obvious failures remain on Parslet (that
is after re-enabling some previously disabled tests, most of which
pass now). This patch also removes the fix from #22, as it's not
needed anymore.
This PR has been sponsored by Ribose Inc.
Describe the bug
When giving StringScanner#scan a multiline (
//m
) regexp, instead of scanning just the next character, it scans characters after a newline too.In Ruby, multiline modifier changes semantics of
.
to mean "any character", not "any character except \n".In JavaScript instead, it changes semantics of
^
and$
to how they work in Ruby even without//m
, so they match beginning/ending either of string or line. Except... there's no\A
or\z
.Opal's StringScanner#scan implementation adds
^
to the beginning of the supplied regexp and copies the flags.All combined cause a hard-to-discover bug. I don't have simple solutions for that issue, maybe except of using lookbehind to simulate
\A
in Opal's clone ofStringScanner
, but that only recently has been implemented in Safari.Opal version: master
To Reproduce
The text was updated successfully, but these errors were encountered: