Repository navigation
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
sou1118
left a comment
There was a problem hiding this comment.
Sorry for the slow review. I've had a lot going on personally and couldn't get to this sooner. Thanks for your patience, and for the fix!
The change to escape_content looks good to me. I checked it against typst compile, and these cases go from failing on main to compiling with this PR:
| change | main |
this PR |
|---|---|---|
add \] |
unexpected closing bracket |
OK |
delete \] |
unexpected closing bracket |
OK |
delete \@b |
label `<b>` does not exist |
OK |
I also didn't see any regressions with \[x], \\, a trailing \, or \] inside raw text.
The only thing I'd like changed is the integration test. It currently passes on main without the fix, so it doesn't guard against this bug. Details and a suggested replacement are in the inline comment.
| #[test] | ||
| fn test_existing_backslash_escape_is_not_double_escaped() { | ||
| // `\*` and `\[` are already literal. Escaping the backslash instead would | ||
| // hand the `*`/`[` back to Typst as markup and reopen the delimiter. | ||
| let old = "Foo bar.\n"; | ||
| let new = "Foo \\*baz* and \\[qux bar.\n"; | ||
| let output = run_diff(old, new); | ||
|
|
||
| assert!( | ||
| !output.contains("\\\\*") && !output.contains("\\\\["), | ||
| "an existing escape must not be escaped a second time: {output}" | ||
| ); | ||
| } |
There was a problem hiding this comment.
I don't think this test catches the bug: it passes on main without the fix. * and [ were never escaped by escape_content, so there was nothing to double-escape. The characters that actually broke are ] (and @ / < on the deleted side, where escape_refs is on).
Also, the input itself isn't valid Typst: in \*baz*, the second * opens strong emphasis that never closes, so typst compile fails with unclosed delimiter even on the new document.
Could you replace it with cases that fail on main? Something like this works for me (passes with your fix, fails without it):
#[test]
fn test_existing_escaped_bracket_is_not_double_escaped() {
// `\]` is already literal. Escaping the backslash would hand the `]`
// back to Typst and close the `#diff-added[...]` block early.
let output = run_diff("Foo bar here.\n", "Foo \\] bar here.\n");
assert!(output.contains("#diff-added[\\] ]"), "{output}");
assert!(!output.contains("\\\\]"), "{output}");
}
#[test]
fn test_existing_escaped_at_is_not_double_escaped_on_deleted_side() {
// The deleted side escapes `@`, so an existing `\@` must not become `\\@`,
// which would turn it back into a reference.
let output = run_diff("A \\@b c d.\n", "A x c d.\n");
assert!(output.contains("#diff-deleted[\\@b]"), "{output}");
assert!(!output.contains("\\\\@"), "{output}");
}There was a problem hiding this comment.
Good point, thanks! I updated the code to use your tests. They now fail on main, but pass after the changes.
escape_content had no case for backslash, so it escaped the backslash of an escape sequence that was already in the source: `\]` became `\\]`, a literal backslash followed by a bare `]` that closes the caller's content block early. Copy escape sequences through whole instead.
949079b to
eb25ea6
Compare
escape_content had no case for backslash, so it escaped the backslash of an escape sequence that was already in the source:
\]became\\], a literal backslash followed by a bare]that closes the caller's content block early. Copy escape sequences through whole instead.Summary by CodeRabbit
\]and\@, now display without extra backslashes.