Skip to content

Commit 125ea02

Browse files
sirlancelotyyx990803
authored andcommitted
[fix] Don't remove newlines during parseText
Since `text` is being used as the key in `cache.get(text)` and the cache is checked *before* newlines were removed, the cache would always miss if the input `text` had *any* newlines. I updated `tagRe` to match tags which contain newlines, and added an extra test case to ensure newlines outside of tags are preserved
1 parent 0709688 commit 125ea02

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/parsers/text.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export function compileRegex () {
2222
var unsafeOpen = escapeRegex(config.unsafeDelimiters[0])
2323
var unsafeClose = escapeRegex(config.unsafeDelimiters[1])
2424
tagRE = new RegExp(
25-
unsafeOpen + '(.+?)' + unsafeClose + '|' +
26-
open + '(.+?)' + close,
25+
unsafeOpen + '([^]+?)' + unsafeClose + '|' +
26+
open + '([^]+?)' + close,
2727
'g'
2828
)
2929
htmlRE = new RegExp(
@@ -52,7 +52,6 @@ export function parseText (text) {
5252
if (hit) {
5353
return hit
5454
}
55-
text = text.replace(/\n/g, '')
5655
if (!tagRE.test(text)) {
5756
return null
5857
}

test/unit/specs/parsers/text_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ var testCases = [
4949
expected: [
5050
{ tag: true, value: 'value', html: false, oneTime: false }
5151
]
52+
},
53+
// new lines preserved outside of tags
54+
{
55+
text: 'hello\n{{value}}\nworld',
56+
expected: [
57+
{ value: 'hello\n' },
58+
{ tag: true, value: 'value', html: false, oneTime: false },
59+
{ value: '\nworld' }
60+
]
5261
}
5362
]
5463

0 commit comments

Comments
 (0)