@@ -6215,8 +6215,8 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) {
6215
6215
return;
6216
6216
}
6217
6217
case 'x': {
6218
- uint8_t byte = peek(parser);
6219
6218
parser->current.end++;
6219
+ uint8_t byte = peek(parser);
6220
6220
6221
6221
if (pm_char_is_hexadecimal_digit(byte)) {
6222
6222
uint8_t value = escape_hexadecimal_digit(byte);
@@ -6239,7 +6239,7 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) {
6239
6239
parser->current.end++;
6240
6240
6241
6241
if (
6242
- (parser->current.end + 4 < parser->end) &&
6242
+ (parser->current.end + 4 <= parser->end) &&
6243
6243
pm_char_is_hexadecimal_digit(parser->current.end[0]) &&
6244
6244
pm_char_is_hexadecimal_digit(parser->current.end[1]) &&
6245
6245
pm_char_is_hexadecimal_digit(parser->current.end[2]) &&
@@ -6250,12 +6250,13 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) {
6250
6250
parser->current.end += 4;
6251
6251
} else if (peek(parser) == '{') {
6252
6252
const uint8_t *unicode_codepoints_start = parser->current.end - 2;
6253
+
6253
6254
parser->current.end++;
6255
+ parser->current.end += pm_strspn_whitespace(parser->current.end, parser->end - parser->current.end);
6254
6256
6255
6257
const uint8_t *extra_codepoints_start = NULL;
6256
6258
int codepoints_count = 0;
6257
6259
6258
- parser->current.end += pm_strspn_whitespace(parser->current.end, parser->end - parser->current.end);
6259
6260
while ((parser->current.end < parser->end) && (*parser->current.end != '}')) {
6260
6261
const uint8_t *unicode_start = parser->current.end;
6261
6262
size_t hexadecimal_length = pm_strspn_hexadecimal_digit(parser->current.end, parser->end - parser->current.end);
@@ -6303,7 +6304,7 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) {
6303
6304
switch (peeked) {
6304
6305
case '?':
6305
6306
parser->current.end++;
6306
- pm_buffer_append_u8(buffer, escape_byte(0x7f, flags | PM_ESCAPE_FLAG_CONTROL ));
6307
+ pm_buffer_append_u8(buffer, escape_byte(0x7f, flags));
6307
6308
return;
6308
6309
case '\\':
6309
6310
if (flags & PM_ESCAPE_FLAG_CONTROL) {
@@ -6336,7 +6337,7 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) {
6336
6337
switch (peeked) {
6337
6338
case '?':
6338
6339
parser->current.end++;
6339
- pm_buffer_append_u8(buffer, escape_byte(0x7f, flags | PM_ESCAPE_FLAG_CONTROL ));
6340
+ pm_buffer_append_u8(buffer, escape_byte(0x7f, flags));
6340
6341
return;
6341
6342
case '\\':
6342
6343
if (flags & PM_ESCAPE_FLAG_CONTROL) {
@@ -6366,28 +6367,24 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) {
6366
6367
parser->current.end++;
6367
6368
uint8_t peeked = peek(parser);
6368
6369
6369
- switch (peeked) {
6370
- case '?':
6371
- parser->current.end++;
6372
- pm_buffer_append_u8(buffer, escape_byte(0x7f, flags | PM_ESCAPE_FLAG_META));
6373
- return;
6374
- case '\\':
6375
- if (flags & PM_ESCAPE_FLAG_META) {
6376
- pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_META_REPEAT);
6377
- return;
6378
- }
6379
- parser->current.end++;
6380
- escape_read(parser, buffer, flags | PM_ESCAPE_FLAG_META);
6381
- return;
6382
- default:
6383
- if (!char_is_ascii_printable(peeked)) {
6384
- pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_META);
6385
- return;
6386
- }
6387
- parser->current.end++;
6388
- pm_buffer_append_u8(buffer, escape_byte(peeked, flags | PM_ESCAPE_FLAG_META));
6370
+ if (peeked == '\\') {
6371
+ if (flags & PM_ESCAPE_FLAG_META) {
6372
+ pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_META_REPEAT);
6389
6373
return;
6374
+ }
6375
+ parser->current.end++;
6376
+ escape_read(parser, buffer, flags | PM_ESCAPE_FLAG_META);
6377
+ return;
6390
6378
}
6379
+
6380
+ if (!char_is_ascii_printable(peeked)) {
6381
+ pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_META);
6382
+ return;
6383
+ }
6384
+
6385
+ parser->current.end++;
6386
+ pm_buffer_append_u8(buffer, escape_byte(peeked, flags | PM_ESCAPE_FLAG_META));
6387
+ return;
6391
6388
}
6392
6389
default: {
6393
6390
if (parser->current.end < parser->end) {
@@ -7873,7 +7870,7 @@ parser_lex(pm_parser_t *parser) {
7873
7870
// and find the next breakpoint.
7874
7871
if (*breakpoint == '\\') {
7875
7872
pm_unescape_type_t unescape_type = lex_mode->as.list.interpolation ? PM_UNESCAPE_ALL : PM_UNESCAPE_MINIMAL;
7876
- size_t difference = pm_unescape_calculate_difference(parser, breakpoint, unescape_type, false );
7873
+ size_t difference = pm_unescape_calculate_difference(parser, breakpoint, unescape_type);
7877
7874
if (difference == 0) {
7878
7875
// we're at the end of the file
7879
7876
breakpoint = NULL;
@@ -8010,7 +8007,7 @@ parser_lex(pm_parser_t *parser) {
8010
8007
// literally. In this case we'll skip past the next character
8011
8008
// and find the next breakpoint.
8012
8009
if (*breakpoint == '\\') {
8013
- size_t difference = pm_unescape_calculate_difference(parser, breakpoint, PM_UNESCAPE_ALL, false );
8010
+ size_t difference = pm_unescape_calculate_difference(parser, breakpoint, PM_UNESCAPE_ALL);
8014
8011
if (difference == 0) {
8015
8012
// we're at the end of the file
8016
8013
breakpoint = NULL;
@@ -8165,7 +8162,7 @@ parser_lex(pm_parser_t *parser) {
8165
8162
// literally. In this case we'll skip past the next character and
8166
8163
// find the next breakpoint.
8167
8164
pm_unescape_type_t unescape_type = parser->lex_modes.current->as.string.interpolation ? PM_UNESCAPE_ALL : PM_UNESCAPE_MINIMAL;
8168
- size_t difference = pm_unescape_calculate_difference(parser, breakpoint, unescape_type, false );
8165
+ size_t difference = pm_unescape_calculate_difference(parser, breakpoint, unescape_type);
8169
8166
if (difference == 0) {
8170
8167
// we're at the end of the file
8171
8168
breakpoint = NULL;
@@ -8341,7 +8338,7 @@ parser_lex(pm_parser_t *parser) {
8341
8338
breakpoint += eol_length;
8342
8339
} else {
8343
8340
pm_unescape_type_t unescape_type = (quote == PM_HEREDOC_QUOTE_SINGLE) ? PM_UNESCAPE_MINIMAL : PM_UNESCAPE_ALL;
8344
- size_t difference = pm_unescape_calculate_difference(parser, breakpoint, unescape_type, false );
8341
+ size_t difference = pm_unescape_calculate_difference(parser, breakpoint, unescape_type);
8345
8342
if (difference == 0) {
8346
8343
// we're at the end of the file
8347
8344
breakpoint = NULL;
0 commit comments