Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix #127 - map lib code globs -> regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Nov 14, 2016
1 parent e0006a9 commit f164cea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
.then(e => {
this.hookConnectionEvents();
if (this._launchAttachArgs.experimentalLibraryCode) {
this.chrome.Debugger.setBlackboxPatterns({ patterns: this._launchAttachArgs.experimentalLibraryCode });
const patterns = this._launchAttachArgs.experimentalLibraryCode.map(glob => utils.pathGlobToBlackboxedRegex(glob));
this.chrome.Debugger.setBlackboxPatterns({ patterns });
}

return Promise.all(this.runConnection());
Expand Down
16 changes: 15 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,22 @@ export function pathToRegex(aPath: string): string {
return aPath;
}

export function pathGlobToBlackboxedRegex(glob: string): string {
return escapeRegexSpecialCharsForBlackbox(glob)
.replace(/\*\*/g, '.*') // ** -> .*
.replace(/([^\.]|^)\*/g, '$1.*') // * -> .*

// Just to simplify
.replace(/\.\*\\\/\.\*/g, '.*') // .*\/.* -> .*
.replace(/\.\*\.\*/g, '.*'); // .*.* -> .*
}

function escapeRegexSpecialChars(str: string): string {
return str.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
return str.replace(/([/\\.?*()^${}|[\]+])/g, '\\$1');
}

function escapeRegexSpecialCharsForBlackbox(str: string): string {
return str.replace(/([/\\.?()^${}|[\]+])/g, '\\$1');
}

export function trimLastNewline(msg: string): string {
Expand Down
26 changes: 26 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,30 @@ suite('Utils', () => {
testPathToRegex('file:///c:\\a\\b.js', 'file:\\/\\/\\/[Cc]:\\\\a\\\\b\\.js');
});
});

suite('pathGlobToRegex', () => {
function testPathGlobToBlackboxedScript(glob: string, expected: string): void {
assert.equal(getUtils().pathGlobToBlackboxedRegex(glob), expected);
}

test('universal', () => {
testPathGlobToBlackboxedScript('*', '.*');
});

test('url', () => {
testPathGlobToBlackboxedScript('http://localhost:8080/node_modules/**/*.js', 'http:\\/\\/localhost:8080\\/node_modules\\/.*\\.js');
});

test('path segment', () => {
testPathGlobToBlackboxedScript('node_modules', 'node_modules');
});

test('file extension', () => {
testPathGlobToBlackboxedScript('*.foo.bar', '.*\\.foo\\.bar');
});

test('escapes special chars except asterisk', () => {
testPathGlobToBlackboxedScript('*.+\\[(', '.*\\.\\+\\\\\\[\\(');
});
});
});

0 comments on commit f164cea

Please sign in to comment.