Skip to content

Commit

Permalink
CN: Fix #860, escape ampersand in pp string HTML
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
dc-mak committed Mar 5, 2025
1 parent 0512fcc commit ee59264
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions backend/cn/lib/pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,12 @@ let document_of_yojson (json : Yojson.Safe.t) : (document, string) Result.t =
| `String str -> Ok (PPrint.arbitrary_string str)
| _ ->
Error ("document_of_yojson: expected `String, found " ^ Yojson.Safe.to_string json)


let string str =
let amp = Str.regexp "&" in
if !html_escapes then (
let str = Str.global_replace amp "&" str in
string str)
else
string str

0 comments on commit ee59264

Please sign in to comment.