Skip to content

Invalid unicode escapes in regexp are not a syntax error #3734

@Earlopain

Description

@Earlopain

For example:

/\u{21!3}/
$ ruby -c test.rb
Syntax OK

$ ruby --parser=parse.y -c test.rb
ruby: test.rb:1: invalid Unicode list: /\u{21!3}/ (SyntaxError)

Prism knows this is invalid but intentionally ignores the error:

prism/src/prism.c

Lines 9810 to 9814 in 3340d87

if (flags & PM_ESCAPE_FLAG_REGEXP) {
// If this is a regular expression, we are going to
// let the regular expression engine handle this
// error instead of us.
pm_buffer_append_bytes(regular_expression_buffer, start, (size_t) (parser->current.end - start));

This is because this regex is valid (invalid escape after comment in extended mode):

/# \u{21!3}/x

At runtime everything is right but it would be nice to also report this at parse-time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects are currently unavailable

    Please try again later

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions