From 0e47c0ee6c797c1b84f36c2a15cb6c3361f13062 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 23 Jun 2022 11:50:32 +0530 Subject: [PATCH] fix #3019 Add word boundary to FK&PK. (#3168) --- src/diagrams/er/parser/erDiagram.jison | 2 +- src/diagrams/er/parser/erDiagram.spec.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/diagrams/er/parser/erDiagram.jison b/src/diagrams/er/parser/erDiagram.jison index 3d7a54fe97..64d395aed4 100644 --- a/src/diagrams/er/parser/erDiagram.jison +++ b/src/diagrams/er/parser/erDiagram.jison @@ -28,7 +28,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili "erDiagram" return 'ER_DIAGRAM'; "{" { this.begin("block"); return 'BLOCK_START'; } \s+ /* skip whitespace in block */ -(?:PK)|(?:FK) return 'ATTRIBUTE_KEY' +\b((?:PK)|(?:FK))\b return 'ATTRIBUTE_KEY' [A-Za-z][A-Za-z0-9\-_]* return 'ATTRIBUTE_WORD' \"[^"]*\" return 'COMMENT'; [\n]+ /* nothing */ diff --git a/src/diagrams/er/parser/erDiagram.spec.js b/src/diagrams/er/parser/erDiagram.spec.js index 20be2fbe1c..1e0a40104f 100644 --- a/src/diagrams/er/parser/erDiagram.spec.js +++ b/src/diagrams/er/parser/erDiagram.spec.js @@ -72,6 +72,19 @@ describe('when parsing ER diagram it...', function () { expect(entities[entity].attributes.length).toBe(1); }); + it('should allow an entity with attribute starting with fk or pk and a comment', function () { + const entity = 'BOOK'; + const attribute1 = 'int fk_title FK'; + const attribute2 = 'string pk_author PK'; + const attribute3 = 'float pk_price PK "comment"'; + + erDiagram.parser.parse( + `erDiagram\n${entity} {\n${attribute1} \n\n${attribute2}\n${attribute3}\n}` + ); + const entities = erDb.getEntities(); + expect(entities[entity].attributes.length).toBe(3); + }); + it('should allow an entity with multiple attributes to be defined', function () { const entity = 'BOOK'; const attribute1 = 'string title';