From: "jeremyevans0 (Jeremy Evans)" Date: 2022-03-26T02:26:58+00:00 Subject: [ruby-core:108082] [Ruby master Bug#18294] error when parsing regexp comment Issue #18294 has been updated by jeremyevans0 (Jeremy Evans). I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/5721 The basic approach is skip the parse.y checks for regexps, because regexp does the same checks. Modify the regexp code to pass the regexp options to a couple of internal functions, and in the function that handles the unescaping, recognize `#` and ignore characters until the end of the line. This becomes complicated, because `#` is allowed as a regular, non-comment character, inside a character class `[]`. So attempt to handle that. Additionally, I found this issue is not limited to extended regexps, it affects all regexps using `(?#` comments. So try to handle those comments as well by ignoring content inside them. I'm not sure the pull request handles all cases, and I'm also not sure it doesn't introduce regressions. It would great if a more knowledgeable committer could review it. The patch is kind of a hack. A better fix would be to integrate the unescaping code with the regexp parsing code, instead of trying to unescape in a first pass, before parsing in a later pass. This would allow the unescaping to be aware of the regexp parser state, making it simple to avoid unescaping when inside a regexp comment. ---------------------------------------- Bug #18294: error when parsing regexp comment https://bugs.ruby-lang.org/issues/18294#change-97040 * Author: thyresias (Thierry Lambert) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [i386-mingw32] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- The following code generates the error "too short escaped multibyte character" ``` ruby _re = / foo # \M-ca /x ``` Removing the \ or doubling it makes the error disappear. Since this is in comment text, I would expect to be able to type anything there: am I missing something? -- https://bugs.ruby-lang.org/ Unsubscribe: