From 61714cbda34151f0b7e1e8ad690778770044f52f Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Sun, 23 May 2021 12:39:06 -0400 Subject: [PATCH] Fixed super minor issue with import pragma (#5521) --- core/modules/parsers/wikiparser/rules/import.js | 2 +- editions/test/tiddlers/tests/test-widget.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/modules/parsers/wikiparser/rules/import.js b/core/modules/parsers/wikiparser/rules/import.js index bce5e1ef3..9556c7af5 100644 --- a/core/modules/parsers/wikiparser/rules/import.js +++ b/core/modules/parsers/wikiparser/rules/import.js @@ -36,7 +36,7 @@ exports.parse = function() { // Move past the pragma invocation this.parser.pos = this.matchRegExp.lastIndex; // Parse the filter terminated by a line break - var reMatch = /(.*)(\r?\n)|$/mg; + var reMatch = /(.*)(?:$|\r?\n)/mg; reMatch.lastIndex = this.parser.pos; var match = reMatch.exec(this.parser.source); this.parser.pos = reMatch.lastIndex; diff --git a/editions/test/tiddlers/tests/test-widget.js b/editions/test/tiddlers/tests/test-widget.js index bd766fe7e..459ec33fe 100755 --- a/editions/test/tiddlers/tests/test-widget.js +++ b/editions/test/tiddlers/tests/test-widget.js @@ -702,6 +702,19 @@ describe("Widget module", function() { expect(wrapper.innerHTML).toBe("

Don't forget me.

"); }); + /** Special case. \import should parse correctly, even if it's + * the only line in the tiddler. Technically doesn't cause a + * visual difference, but may affect plugins if it doesn't. + */ + it("should work when import pragma is standalone", function() { + var wiki = new $tw.Wiki(); + var text = "\\import [prefix[XXX]]"; + var parseTreeNode = parseText(text,wiki); + // Test the resulting parse tree node, since there is no + // rendering which may expose a problem. + expect(parseTreeNode.children[0].attributes.filter.value).toBe('[prefix[XXX]]'); + }); + /** This test reproduces issue #4504. * * The importvariable widget was creating redundant copies into