From: merch-redmine@... Date: 2020-11-23T20:08:00+00:00 Subject: [ruby-core:101031] [Ruby master Bug#17340] /\p{/ matches newline instead of throwing syntax error Issue #17340 has been updated by jeremyevans0 (Jeremy Evans). It turns out the regexp behavior depends on the encoding: ``` $ ruby -ve 'p(/\p{/u.match("\n"))' ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-openbsd] # $ ruby -ve 'p(/\p{/n.match("\n"))' ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-openbsd] -e:1: internal parser error (bug): /\p{/ ``` I agree with you about the appropriate place to fix this. I've submitted a pull request to fix it: https://github.com/ruby/ruby/pull/3807 ---------------------------------------- Bug #17340: /\p{/ matches newline instead of throwing syntax error https://bugs.ruby-lang.org/issues/17340#change-88702 * Author: jirkamarsik (Jirka Marsik) * Status: Open * Priority: Normal * ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- The regular expression `/\p{/` matches newline characters instead of reporting a syntax error. ``` irb(main):001:0> /\p{/.match("\n") => # ``` The issue stems from the function `fetch_char_property_to_ctype` in `regparse.c`. If the Unicode character property escape is not terminated with a right brace or some of the other unacceptable characters, the method will return 0 and will not be considered a failure. The number 0 is then interpreted as a `ctype` code which stands for the newline character property. Thus, this expression will end up matching newlines. I would guess that the intended behavior here would be to report a syntax error in the regular expression. -- https://bugs.ruby-lang.org/ Unsubscribe: