@@ -12115,9 +12115,28 @@ parser_lex(pm_parser_t *parser) {
1211512115 pm_regexp_token_buffer_t token_buffer = { 0 };
1211612116
1211712117 while (breakpoint != NULL) {
12118+ uint8_t term = lex_mode->as.regexp.terminator;
12119+ bool is_terminator = (*breakpoint == term);
12120+
12121+ // If the terminator is newline, we need to consider \r\n _also_ a newline
12122+ // For example: `%\nfoo\r\n`
12123+ // The string should be "foo", not "foo\r"
12124+ if (*breakpoint == '\r' && peek_at(parser, breakpoint + 1) == '\n') {
12125+ if (term == '\n') {
12126+ is_terminator = true;
12127+ }
12128+
12129+ // If the terminator is a CR, but we see a CRLF, we need to
12130+ // treat the CRLF as a newline, meaning this is _not_ the
12131+ // terminator
12132+ if (term == '\r') {
12133+ is_terminator = false;
12134+ }
12135+ }
12136+
1211812137 // If we hit the terminator, we need to determine what kind of
1211912138 // token to return.
12120- if (*breakpoint == lex_mode->as.regexp.terminator ) {
12139+ if (is_terminator ) {
1212112140 if (lex_mode->as.regexp.nesting > 0) {
1212212141 parser->current.end = breakpoint + 1;
1212312142 breakpoint = pm_strpbrk(parser, parser->current.end, breakpoints, parser->end - parser->current.end, false);
@@ -12347,20 +12366,21 @@ parser_lex(pm_parser_t *parser) {
1234712366 continue;
1234812367 }
1234912368
12350- bool is_terminator = (*breakpoint == lex_mode->as.string.terminator);
12369+ uint8_t term = lex_mode->as.string.terminator;
12370+ bool is_terminator = (*breakpoint == term);
1235112371
1235212372 // If the terminator is newline, we need to consider \r\n _also_ a newline
12353- // For example: `%\nfoo\r\n`
12354- // The string should be " foo" , not " foo\r"
12373+ // For example: `%r \nfoo\r\n`
12374+ // The string should be / foo/ , not / foo\r/
1235512375 if (*breakpoint == '\r' && peek_at(parser, breakpoint + 1) == '\n') {
12356- if (lex_mode->as.string.terminator == '\n') {
12376+ if (term == '\n') {
1235712377 is_terminator = true;
1235812378 }
1235912379
1236012380 // If the terminator is a CR, but we see a CRLF, we need to
1236112381 // treat the CRLF as a newline, meaning this is _not_ the
1236212382 // terminator
12363- if (lex_mode->as.string.terminator == '\r') {
12383+ if (term == '\r') {
1236412384 is_terminator = false;
1236512385 }
1236612386 }
0 commit comments