Skip to content

Commit

Permalink
fix(sexp): Accept another digit after an \x.. or \... escape sequence…
Browse files Browse the repository at this point in the history
… in strings

The two cases that this modifies are meant to catch the issue of
"unterminated ... escape sequences" but, due to the use of '*', they
also caught the cases where the escape sequence was followed by another
digit

Signed-off-by: Samuel Hym <samuel.hym@rustyne.lautre.net>
  • Loading branch information
shym authored and rgrinberg committed Dec 15, 2022
1 parent 1c722f7 commit a237caa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Fix the parsing of decimal and hexadecimal escape literals in `dune`,
`dune-package`, and other dune s-expression based files (#6710, @shym)

- Report an error if `dune init ...` would create a "dune" file in a location
which already contains a "dune" directory (#6705, @gridbugs)

Expand Down
4 changes: 2 additions & 2 deletions src/dune_sexp/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ and escape_sequence = parse
| digit digit digit
{ error lexbuf "escape sequence in quoted string out of range" ~delta:(-1);
}
| digit*
| digit digit?
{ error lexbuf "unterminated decimal escape sequence" ~delta:(-1);
}
| 'x' (hexdigit as c1) (hexdigit as c2)
{ let v = eval_hex_escape c1 c2 in
Template.Buffer.add_text_c (Char.chr v);
Other
}
| 'x' hexdigit*
| 'x' hexdigit?
{ error lexbuf "unterminated hexadecimal escape sequence" ~delta:(-1);
}
| _
Expand Down
4 changes: 2 additions & 2 deletions test/expect-tests/dune_lang/sexp_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ Ok [ "bar%foo" ]
let%expect_test _ =
parse {|"\0000"|};
[%expect {|
Error "unterminated decimal escape sequence"
Ok [ "\0000" ]
|}]

let%expect_test _ =
parse {|"\x000"|};
[%expect {|
Error "unterminated hexadecimal escape sequence"
Ok [ "\0000" ]
|}]

(* Printing tests *)
Expand Down

0 comments on commit a237caa

Please sign in to comment.