Allow escaped quotations in strings

This commit is contained in:
Ibrahim Wassouf 2023-07-24 22:43:06 -03:00
parent 47c100809b
commit 20cd685ae3
4 changed files with 8 additions and 8 deletions

View File

@ -91,6 +91,7 @@ export const addVertex = function (_id, textObj, type, style, classes, dir, prop
if (textObj !== undefined) {
config = configApi.getConfig();
txt = sanitizeText(textObj.text.trim());
txt = textObj.type === 'string' ? txt.replaceAll('\\"', '"') : txt;
vertices[id].labelType = textObj.type;
// strip quotes if string starts and ends with a quote
if (txt[0] === '"' && txt[txt.length - 1] === '"') {

View File

@ -24,7 +24,7 @@ A["\`The cat in **the** hat\`"]-- "\`The *bat* in the chat\`" -->B["The dog in t
expect(vert['A'].labelType).toBe('markdown');
expect(vert['B'].id).toBe('B');
expect(vert['B'].text).toBe('The dog in the hog');
expect(vert['B'].labelType).toBe('text');
expect(vert['B'].labelType).toBe('string');
expect(edges.length).toBe(2);
expect(edges[0].start).toBe('A');
expect(edges[0].end).toBe('B');

View File

@ -717,9 +717,8 @@ describe('[Text] when parsing', () => {
it('should parse escaped quotes in a string state', function () {
//prettier-ignore
const str = 'graph TD; A["This is a \"()\" in text"];'; //eslint-disable-line no-useless-escape
flow.parser.parse(str);
expect(flow.parser.getVertices[0].text).toBe('This is a "()" in text');
flow.parser.parse('graph TD; A["This is a \\"()\\" in text"];'); //eslint-disable-line no-useless-escape
const vert = flow.parser.yy.getVertices();
expect(vert['A'].text).toBe('This is a "()" in text');
});
});

View File

@ -61,9 +61,9 @@ Function arguments are optional: 'call <callbackname>()' simply executes 'callba
<md_string>[^`"]+ { return "MD_STR";}
<md_string>[`]["] { this.popState();}
<*>["][`] { this.begin("md_string");}
<string>(\\(?=\")\"|[^"])+ return "STR";
<string>["] this.popState();
<string>[^"]+ return "STR";
<*>["] this.pushState("string");
<*>["] this.pushState("string");
"style" return 'STYLE';
"default" return 'DEFAULT';
"linkStyle" return 'LINKSTYLE';
@ -481,7 +481,7 @@ text: textToken
| text textToken
{ $$={text:$text.text+''+$textToken, type: $text.type};}
| STR
{$$={text: $STR, type: 'text'};}
{ $$ = {text: $STR, type: 'string'};}
| MD_STR
{ $$={text: $MD_STR, type: 'markdown'};}
;