Skip to content

Commit

Permalink
Escape backslashes for Graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaines committed Feb 18, 2024
1 parent 81c0f15 commit 8e02704
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export function formatSentence(sentence, info) {
}

export function escapeString(string) {
return string.replace(/[&<>"]/g, function(name) {
return string.replaceAll(/[&<>"]/g, function(name) {
return ESCAPE[name];
});
}).replaceAll("\\", "\\\\");
}

function barePrettifySymbol(symbol) {
Expand Down
3 changes: 2 additions & 1 deletion test/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ describe("helpers", function() {

it("double escapes other nonprinting characters", function() {
let info = {
terminals: new Set(["\n"]),
terminals: new Set(["\n", "\\"]),
nonterminals: new Set()
};

assert.deepStrictEqual(bareFormatSymbol("\n", info), "\\\\n");
assert.deepStrictEqual(bareFormatSymbol("\\", info), "\\\\");
});

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

0 comments on commit 8e02704

Please sign in to comment.