Skip to content

Commit a237caa

Browse files
shymrgrinberg
authored andcommitted
fix(sexp): Accept another digit after an \x.. or \... escape sequence 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>
1 parent 1c722f7 commit a237caa

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Unreleased
22
----------
33

4+
- Fix the parsing of decimal and hexadecimal escape literals in `dune`,
5+
`dune-package`, and other dune s-expression based files (#6710, @shym)
6+
47
- Report an error if `dune init ...` would create a "dune" file in a location
58
which already contains a "dune" directory (#6705, @gridbugs)
69

src/dune_sexp/lexer.mll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,15 @@ and escape_sequence = parse
320320
| digit digit digit
321321
{ error lexbuf "escape sequence in quoted string out of range" ~delta:(-1);
322322
}
323-
| digit*
323+
| digit digit?
324324
{ error lexbuf "unterminated decimal escape sequence" ~delta:(-1);
325325
}
326326
| 'x' (hexdigit as c1) (hexdigit as c2)
327327
{ let v = eval_hex_escape c1 c2 in
328328
Template.Buffer.add_text_c (Char.chr v);
329329
Other
330330
}
331-
| 'x' hexdigit*
331+
| 'x' hexdigit?
332332
{ error lexbuf "unterminated hexadecimal escape sequence" ~delta:(-1);
333333
}
334334
| _

test/expect-tests/dune_lang/sexp_tests.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ Ok [ "bar%foo" ]
195195
let%expect_test _ =
196196
parse {|"\0000"|};
197197
[%expect {|
198-
Error "unterminated decimal escape sequence"
198+
Ok [ "\0000" ]
199199
|}]
200200

201201
let%expect_test _ =
202202
parse {|"\x000"|};
203203
[%expect {|
204-
Error "unterminated hexadecimal escape sequence"
204+
Ok [ "\0000" ]
205205
|}]
206206

207207
(* Printing tests *)

0 commit comments

Comments
 (0)