Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ Diagram.Note.prototype.hasManyActors = function() {
};

Diagram.unescape = function(s) {
// Turn "\\n" into "\n"
return s.trim().replace(/^"(.*)"$/m, '$1').replace(/\\n/gm, '\n');
var unescaped = s.trim()
.replace(/^"(.*)"$/m, '$1') // remove quotes on quoted actors
.replace(/\\n/gm, '\n') // turn "\\n" into "\n"
.replace(/\\"/gm, '"'); // turn '\"' into '"'
return unescaped;
};

Diagram.LINETYPE = {
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.jison
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"title" return 'title';
"," return ',';
[^\->:,\r\n"]+ return 'ACTOR';
\"[^"]+\" return 'ACTOR';
\"(([^\"]|\\\")*[^\\])?\" return 'ACTOR'; // quoted actors
"--" return 'DOTLINE';
"-" return 'LINE';
">>" return 'OPENARROW';
Expand Down
5 changes: 5 additions & 0 deletions test/grammar-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ test('Quoted names', function() {
assertSingleActor(Diagram.parse('Participant "->:"'), '->:');
});

test('Quoted names with escape characters', function() {
assertSingleArrow(Diagram.parse('"->\\":"->B: M'), ARROWTYPE.FILLED, LINETYPE.SOLID,
'->":', 'B', 'M');
});

test('API', function() {
// Public API
ok(typeof Diagram.parse == 'function');
Expand Down