diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-19 01:35:21 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-19 01:35:21 +0900 |
commit | 67dd52d59cde0d2f1ebb3e299b605ed239b59f5b (patch) | |
tree | 6cc6d456897018157e6d5ec256f16885dfa6a118 /parse.y | |
parent | e8e7ff1333b9b32d72a1d8f789a186d58c811420 (diff) | |
download | ruby-67dd52d59cde0d2f1ebb3e299b605ed239b59f5b.tar.gz |
[Bug #19539] Match heredoc identifier from end of line
Not to ignore leading spaces in indented heredoc identifier.
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -8200,19 +8200,19 @@ parser_dedent_string(VALUE self, VALUE input, VALUE width) static int whole_match_p(struct parser_params *p, const char *eos, long len, int indent) { - const char *ptr = p->lex.pbeg; - long n; + const char *beg = p->lex.pbeg; + const char *ptr = p->lex.pend; - if (indent) { - while (*ptr && ISSPACE(*ptr)) ptr++; + if (ptr - beg < len) return FALSE; + if (ptr > beg && ptr[-1] == '\n') { + if (--ptr > beg && ptr[-1] == '\r') --ptr; + if (ptr - beg < len) return FALSE; } - n = p->lex.pend - (ptr + len); - if (n < 0) return FALSE; - if (n > 0 && ptr[len] != '\n') { - if (ptr[len] != '\r') return FALSE; - if (n <= 1 || ptr[len+1] != '\n') return FALSE; + if (strncmp(eos, ptr -= len, len)) return FALSE; + if (indent) { + while (beg < ptr && ISSPACE(*beg)) beg++; } - return strncmp(eos, ptr, len) == 0; + return beg == ptr; } static int |