Skip to content

Commit c914c62

Browse files
committed
Escape backslashes for Graphviz
1 parent 81c0f15 commit c914c62

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/components/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ export function formatSentence(sentence, info) {
123123
}
124124

125125
export function escapeString(string) {
126-
return string.replace(/[&<>"]/g, function(name) {
126+
return string.replaceAll(/[&<>"]/g, function(name) {
127127
return ESCAPE[name];
128-
});
128+
}).replaceAll("\\", "\\\\");
129129
}
130130

131131
function barePrettifySymbol(symbol) {

test/helpers.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ describe("helpers", function() {
6666

6767
it("double escapes other nonprinting characters", function() {
6868
let info = {
69-
terminals: new Set(["\n"]),
69+
terminals: new Set(["\n", "\\"]),
7070
nonterminals: new Set()
7171
};
7272

7373
assert.deepStrictEqual(bareFormatSymbol("\n", info), "\\\\n");
74+
assert.deepStrictEqual(bareFormatSymbol("\\", info), "\\\\");
7475
});
7576

7677
it("refuses to format an unknown symbol", function() {

0 commit comments

Comments
 (0)