Skip to content

Commit a58c9f8

Browse files
committed
fix(brocolli): escape special regexp characters when building regexps
Special regexp tokens were allowed unchanged previously, which incorrectly broke the include/exclude behaviour. Now, they're escaped first. Closes angular#1721 Closes angular#1752
1 parent 624a33f commit a58c9f8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

tools/broccoli/tree-differ.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ describe('TreeDiffer', () => {
151151
'dir1': {
152152
'file-1.ts': mockfs.file({content: 'file-1.ts content', mtime: new Date(1000)}),
153153
'file-1.cs': mockfs.file({content: 'file-1.cs content', mtime: new Date(1000)}),
154+
'file-1d.cs': mockfs.file({content: 'file-1d.cs content', mtime: new Date(1000)}),
154155
'file-1.d.cs': mockfs.file({content: 'file-1.d.cs content', mtime: new Date(1000)}),
155156
'file-2.md': mockfs.file({content: 'file-2.md content', mtime: new Date(1000)}),
156157
'file-3.ts': mockfs.file({content: 'file-3.ts content', mtime: new Date(1000)}),
@@ -166,7 +167,8 @@ describe('TreeDiffer', () => {
166167

167168
let diffResult = differ.diffTree();
168169

169-
expect(diffResult.changedPaths).toEqual(['file-1.cs', 'file-1.ts', 'file-3.ts']);
170+
expect(diffResult.changedPaths)
171+
.toEqual(['file-1.cs', 'file-1.ts', 'file-1d.cs', 'file-3.ts']);
170172

171173
// change two files
172174
testDir['dir1']['file-1.ts'] = mockfs.file({content: 'new content', mtime: new Date(1000)});

tools/broccoli/tree-differ.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class TreeDiffer {
2222

2323
function combine(prev, curr) {
2424
if (curr.charAt(0) !== ".") throw new TypeError("Extension must begin with '.'");
25-
curr = '(' + curr + ')';
25+
let kSpecialRegexpChars = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;
26+
curr = '(' + curr.replace(kSpecialRegexpChars, '\\$&') + ')';
2627
return prev ? (prev + '|' + curr) : curr;
2728
}
2829
}

0 commit comments

Comments
 (0)