Skip to content

Commit ee59264

Browse files
committed
CN: Fix #860, escape ampersand in pp string HTML
We don't have automatic testing for HTML output (yet) and so this is the test case: ```c void f(void) { int region = 1; /*@ assert(false); @*/ } ``` If the ampersand is not escaped, on the last page of the output, the &region turns into "(R)ion".
1 parent 0512fcc commit ee59264

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

backend/cn/lib/pp.ml

+9
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,12 @@ let document_of_yojson (json : Yojson.Safe.t) : (document, string) Result.t =
349349
| `String str -> Ok (PPrint.arbitrary_string str)
350350
| _ ->
351351
Error ("document_of_yojson: expected `String, found " ^ Yojson.Safe.to_string json)
352+
353+
354+
let string str =
355+
let amp = Str.regexp "&" in
356+
if !html_escapes then (
357+
let str = Str.global_replace amp "&" str in
358+
string str)
359+
else
360+
string str

0 commit comments

Comments
 (0)