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

A regexp with \K doesn't work in JRuby #4871

Closed
thallgren opened this issue Nov 28, 2017 · 9 comments
Closed

A regexp with \K doesn't work in JRuby #4871

thallgren opened this issue Nov 28, 2017 · 9 comments
Labels

Comments

@thallgren
Copy link

@thallgren thallgren commented Nov 28, 2017

Environment

jruby-9.1.7.0 running on Linux 4.13.13-100.fc25.x86_64 #1 SMP Wed Nov 15 17:33:19 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Expected Behavior

The text matched by the part of the regex to the left of the \K is omitted from the overall regex match. Other than that the regex is matched normally from left to right.

$ irb
2.3.1 :001 > 'street'.match( /s\Kt/)
 => #<MatchData "t"> 

Actual Behavior

\K does not match anything when using JRuby.

$ irb
jruby-9.1.7.0 :001 > 'street'.match( /s\Kt/)
 => nil 
@headius
Copy link
Member

@headius headius commented Nov 28, 2017

Huh, I'm not familiar with \K. Another bit we need to get into Joni.

@headius headius added this to the JRuby 9.2.0.0 milestone Nov 28, 2017
@thallgren
Copy link
Author

@thallgren thallgren commented Nov 28, 2017

@headius, I must admit, I had never encountered \K either. I found this problem (and the one regarding \X) by testing diffs between Java and Ruby on Regular-Expressions.info. Most headings in that TOC links to a page where the compared flavors can be selected at the top. I found it to be quite helpful.

@lopex
Copy link
Member

@lopex lopex commented Nov 28, 2017

@headius headius modified the milestones: JRuby 9.2.0.0, JRuby 9.1.15.0 Nov 28, 2017
@headius headius added the core label Nov 28, 2017
@headius headius closed this in f976136 Nov 29, 2017
@thallgren
Copy link
Author

@thallgren thallgren commented May 21, 2019

AFAICT, this isn't completely fixed. When running my example I get a warning Unknown escape \K is ignored. I'm using joni-2.1.27 and the subsequent match fails.

unknownEscWarn:145, ScanEnvironment (org.joni)
convertBackslashValue:129, ScanEnvironment (org.joni)
fetchEscapedValueBackSlash:184, Lexer (org.joni)
fetchEscapedValue:179, Lexer (org.joni)
fetchToken:1166, Lexer (org.joni)
parseStringLoop:1090, Parser (org.joni)
parseExpTkByte:1085, Parser (org.joni)
parseExp:801, Parser (org.joni)
parseBranch:1342, Parser (org.joni)
parseSubExp:1368, Parser (org.joni)
parseRegexp:1401, Parser (org.joni)
compile:78, Analyser (org.joni)
<init>:155, Regex (org.joni)
<init>:134, Regex (org.joni)
<init>:120, Regex (org.joni)
<init>:100, Regex (org.joni)
@lopex
Copy link
Member

@lopex lopex commented May 21, 2019

There was indeed a break missing for \K in the lexer. Fixed in jruby/joni@ee4bafb

@lopex
Copy link
Member

@lopex lopex commented May 21, 2019

joni-2.1.28 is released

@thallgren
Copy link
Author

@thallgren thallgren commented May 22, 2019

Thanks. Works like a charm!

@lopex
Copy link
Member

@lopex lopex commented May 22, 2019

@thallgren, can you show the case that was not matching (or a reduced form of it), se we can plug it into our test suite ?
For now, we're running all of Onigmo's suite for \K at https://github.com/jruby/joni/blob/master/test/org/joni/test/TestU8.java#L102

@thallgren
Copy link
Author

@thallgren thallgren commented May 23, 2019

My test is for an evaluator for the Puppet type system, written in Java. It has its own Regexp and Matcher classes to wrap the Onigmo ones so the test will need to be rewritten to suit your style. This is the test that failed: https://github.com/puppetlabs/pcore-java/blob/b234d044d41b3db73aefa478c7ede779b073d27f/src/test/java/com/puppet/pcore/regex/RegexpTest.java#L189

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.