Skip to content

Commit

Permalink
Merge pull request #91 from posthtml/escape-delimiters
Browse files Browse the repository at this point in the history
fix: escape custom delimiters when ignoring expressions
  • Loading branch information
Scrum authored Jun 30, 2020
2 parents d23bf91 + 53c901e commit c50750a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
function escapeRegexpString (input) {
// match Operators
const match = /[|\\{}()[\]^$+*?.]/
const match = /[|\\{}()[\]^$+*?.]/g

return input.replace(match, '\\$&')
}
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ module.exports = function postHTMLExpressions (options) {
delimitersSettings[1] = delimiters[0]
}

delimitersReplace = new RegExp(`@${delimitersSettings[1].text[0]}`, 'g')
unescapeDelimitersReplace = new RegExp(`@${delimitersSettings[0].text[0]}`, 'g')
delimitersReplace = new RegExp(`@${escapeRegexpString(delimitersSettings[1].text[0])}`, 'g')
unescapeDelimitersReplace = new RegExp(`@${escapeRegexpString(delimitersSettings[0].text[0])}`, 'g')

// kick off the parsing
return function (tree) {
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/custom_delimiters.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
x {% test %} x {% 1 + 1 %} x
<p class="x {% test %} x">x {% test %} x</p>
{{% 'x&x' %}}
x %[ test ]% x %[ 1 + 1 ]% x
<p class="x %[ test ]% x">x %[ test ]% x</p>
%[[ 'x&x' ]]%
4 changes: 2 additions & 2 deletions test/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ test('Unescaped', (t) => {

test('Delimiters', (t) => {
return process(t, 'custom_delimiters', {
delimiters: ['{%', '%}'],
unescapeDelimiters: ['{{%', '%}}'],
delimiters: ['%[', ']%'],
unescapeDelimiters: ['%[[', ']]%'],
locals: { test: 'wow' }
})
})
Expand Down

0 comments on commit c50750a

Please sign in to comment.