|
@@ -501,13 +501,15 @@ let unescape s =
|
|
|
Buffer.add_char b c;
|
|
|
inext := !inext + 2;
|
|
|
| 'x' ->
|
|
|
- let hex = String.sub s (i+1) 2 in
|
|
|
- let u = (try (int_of_string ("0x" ^ hex)) with _ -> fail None) in
|
|
|
+ let fail_no_hex () = fail (Some "Must be followed by a hexadecimal sequence.") in
|
|
|
+ let hex = try String.sub s (i+1) 2 with _ -> fail_no_hex () in
|
|
|
+ let u = (try (int_of_string ("0x" ^ hex)) with _ -> fail_no_hex ()) in
|
|
|
if u > 127 then
|
|
|
fail (Some ("Values greater than \\x7f are not allowed. Use \\u00" ^ hex ^ " instead."));
|
|
|
UTF8.add_uchar b (UChar.uchar_of_int u);
|
|
|
inext := !inext + 2;
|
|
|
| 'u' ->
|
|
|
+ let fail_no_hex () = fail (Some "Must be followed by a hexadecimal sequence enclosed in curly brackets.") in
|
|
|
let (u, a) =
|
|
|
try
|
|
|
(int_of_string ("0x" ^ String.sub s (i+1) 4), 4)
|
|
@@ -515,10 +517,12 @@ let unescape s =
|
|
|
assert (s.[i+1] = '{');
|
|
|
let l = String.index_from s (i+3) '}' - (i+2) in
|
|
|
let u = int_of_string ("0x" ^ String.sub s (i+2) l) in
|
|
|
- assert (u <= 0x10FFFF);
|
|
|
+ if u > 0x10FFFF then
|
|
|
+ fail (Some "Maximum allowed value for unicode escape sequence is \\u{10FFFF}");
|
|
|
(u, l+2)
|
|
|
- with _ ->
|
|
|
- fail None
|
|
|
+ with
|
|
|
+ | Invalid_escape_sequence (c,i,msg) as e -> raise e
|
|
|
+ | _ -> fail_no_hex ()
|
|
|
in
|
|
|
UTF8.add_uchar b (UChar.uchar_of_int u);
|
|
|
inext := !inext + a;
|