Skip to content

Commit f36add8

Browse files
committed
Fix handling of masks
1 parent a3afb04 commit f36add8

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var _ = require('lodash'),
1212
HtmlDiff.prototype.tokenize = function (html) {
1313
html = modifyHtmlAccordingToOptions(html, this.options);
1414

15-
return _.filter(html.split(/({{.+?[^\\]}}(?!})|[{}=:;,<>"'\[\]\/]|\s+)/));
15+
return _.filter(html.split(/({{.+?[^\\]}}(?!})|[{}\(\)=:;,<>"'\[\]\/]|\s+)/));
1616
};
1717

1818
/**

lib/utils/mask.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*
55
* {{RegExp}}
66
*/
7-
var MASK_REGEXP = /(.*){{(.+[^\\])}}(?!})(.*)/;
7+
var MASK_REGEXP = /(.*){{(.+[^\\])}}(?!})(.*)/,
8+
specialСhars = /([^A-Za-zА-Яа-я0-9_\-\s])/g;
89

910
/**
1011
* Checks whether the given part of the diff should be added or removed
@@ -32,7 +33,11 @@ function _revealMasks(diff) {
3233

3334
if (!matchedMask) continue;
3435

35-
var regExp = new RegExp('^' + matchedMask[1] + matchedMask[2] + matchedMask[3] + '$');
36+
var regExp = new RegExp('^' +
37+
matchedMask[1].replace(specialСhars, '\\$1') +
38+
matchedMask[2] +
39+
matchedMask[3].replace(specialСhars, '\\$1') + '$');
40+
3641
if (currPart.added && nextPart && nextPart.removed) {
3742
if (nextPart.value.match(regExp)) {
3843
nextPart.removed = undefined;

test/diff/fixtures/first/mask.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
AZ<meta charset="UTF-32">
2+
<span style="#url{1,3}+ ({{\d}})">
23
<div id="blah{{\d+}}blah"></div>bl{{\}}{=ah 5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
{{[A-Z]+}}<meta charset="{{UTF-\d{1,2}}}">
2+
<span style="#url{1,3}+ (1)">
23
<div id="blah12345blah"></div>{{bl\{\{\\\}}{=ah\s\d}}

0 commit comments

Comments
 (0)