diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-08-28 09:33:01 -0400 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-08-28 10:50:46 -0400 |
| commit | 4c5a1dad0a7e9fb70a830d9312352b855abfc7cb (patch) | |
| tree | 16b58e2c2943febee0290ab00f0e7a832412a29c | |
| parent | 91c6c2bdb544a84313030809d7fcd32da7e17a29 (diff) | |
[PRISM] Check length of line for shebang
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11475
| -rw-r--r-- | prism/prism.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/prism/prism.c b/prism/prism.c index 9ab45f1cc3..ff5d5c2ccc 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -21961,10 +21961,10 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm // If the first two bytes of the source are a shebang, then we'll indicate // that the encoding comment is at the end of the shebang. - if (peek(parser) == '#' && peek_offset(parser, 1) == '!') { - const uint8_t *newline = next_newline(parser->start, parser->end - parser->start); - size_t length = (size_t) ((newline != NULL ? newline : parser->end) - parser->start); + const uint8_t *newline = next_newline(parser->start, parser->end - parser->start); + size_t length = (size_t) ((newline != NULL ? newline : parser->end) - parser->start); + if (length > 2 && parser->current.end[0] == '#' && parser->current.end[1] == '!') { const char *engine; if ((engine = pm_strnstr((const char *) parser->start, "ruby", length)) != NULL) { if (newline != NULL) { |
