My working unpac space for OCaml projects in development
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add legacy octal escape sequence support in strings

- Parse \0-\7 escape sequences in non-strict mode
- Multi-digit octal escapes: \00, \123, etc.
- Properly reject in strict mode

Test262: 48,352/52,896 (91.4%)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+25 -4
+25 -4
lib/quickjs/parser/lexer.ml
··· 474 474 | Some 'b' -> Source.cursor_advance cursor; '\b' 475 475 | Some 'f' -> Source.cursor_advance cursor; '\x0c' 476 476 | Some 'v' -> Source.cursor_advance cursor; '\x0b' 477 - | Some '0' -> 477 + | Some c when c >= '0' && c <= '7' -> 478 + (* Legacy octal escape sequence - allowed in non-strict mode *) 479 + if lexer.strict_mode && c <> '0' then 480 + error lexer Legacy_octal_in_strict_mode; 481 + let value = ref (Char.code c - Char.code '0') in 478 482 Source.cursor_advance cursor; 479 - (* \0 is NUL only if not followed by another digit *) 483 + (* Check for more octal digits *) 484 + let first_digit = Char.code c - Char.code '0' in 480 485 (match Source.cursor_peek cursor with 481 - | Some c when is_digit c -> error lexer (Invalid_escape_sequence "\\0...") 482 - | _ -> '\x00') 486 + | Some c2 when c2 >= '0' && c2 <= '7' -> 487 + if lexer.strict_mode then 488 + error lexer Legacy_octal_in_strict_mode; 489 + value := !value * 8 + (Char.code c2 - Char.code '0'); 490 + Source.cursor_advance cursor; 491 + (* Check for third digit - only if first digit is 0-3 *) 492 + if first_digit <= 3 then begin 493 + match Source.cursor_peek cursor with 494 + | Some c3 when c3 >= '0' && c3 <= '7' -> 495 + value := !value * 8 + (Char.code c3 - Char.code '0'); 496 + Source.cursor_advance cursor 497 + | _ -> () 498 + end 499 + | Some c2 when is_digit c2 -> 500 + (* \0 followed by non-octal digit 8 or 9 - just the \0, digit stays *) 501 + () 502 + | _ -> ()); 503 + Char.chr (!value land 0xFF) 483 504 | Some 'x' -> 484 505 Source.cursor_advance cursor; 485 506 scan_hex_escape lexer 2