Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Error when trying to set a breakpoint in index.html #1029

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/common/urlUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ describe('urlUtils', () => {
'file:\\/\\/\\/[Cc]:\\/foo\\/(?:①|%E2%91%A0)(?:Ⅻ|%E2%85%AB)(?:ㄨ|%E3%84%A8)(?:ㄩ|%E3%84%A9)(?: |%20)(?:啊|%E5%95%8A)(?:阿|%E9%98%BF)(?:鼾|%E9%BC%BE)(?:齄|%E9%BD%84)(?:丂|%E4%B8%82)(?:丄|%E4%B8%84)(?:狚|%E7%8B%9A)(?:狛|%E7%8B%9B)(?:狜|%E7%8B%9C)(?:狝|%E7%8B%9D)(?:﨨|%EF%A8%A8)(?:﨩|%EF%A8%A9)(?:ˊ|%CB%8A)(?:ˋ|%CB%8B)(?:˙|%CB%99)(?:–|%E2%80%93)(?:⿻|%E2%BF%BB)(?:〇|%E3%80%87)(?:㐀|%E3%90%80)(?:㐁|%E3%90%81)(?:䶴|%E4%B6%B4)(?:䶵|%E4%B6%B5)U1(?:\\[|%5B)(?:|%EE%80%A5)(?:|%EE%80%A6)(?:|%EE%80%A7)(?:|%EE%80%B8)(?:|%EE%80%B9)(?:\\]|%5D)U2(?:\\[|%5B)(?:|%EE%89%9A)(?:|%EE%89%9B)(?:|%EE%89%AC)(?:|%EE%89%AD)(?:\\]|%5D)U3(?:\\[|%5B)(?:|%EE%93%BE)(?:|%EE%93%BF)(?:|%EE%94%80)(?:|%EE%94%8B)(?:|%EE%94%8C)(?:\\]|%5D)\\.js|[Cc]:\\\\foo\\\\(?:①|%E2%91%A0)(?:Ⅻ|%E2%85%AB)(?:ㄨ|%E3%84%A8)(?:ㄩ|%E3%84%A9)(?: |%20)(?:啊|%E5%95%8A)(?:阿|%E9%98%BF)(?:鼾|%E9%BC%BE)(?:齄|%E9%BD%84)(?:丂|%E4%B8%82)(?:丄|%E4%B8%84)(?:狚|%E7%8B%9A)(?:狛|%E7%8B%9B)(?:狜|%E7%8B%9C)(?:狝|%E7%8B%9D)(?:﨨|%EF%A8%A8)(?:﨩|%EF%A8%A9)(?:ˊ|%CB%8A)(?:ˋ|%CB%8B)(?:˙|%CB%99)(?:–|%E2%80%93)(?:⿻|%E2%BF%BB)(?:〇|%E3%80%87)(?:㐀|%E3%90%80)(?:㐁|%E3%90%81)(?:䶴|%E4%B6%B4)(?:䶵|%E4%B6%B5)U1(?:\\[|%5B)(?:|%EE%80%A5)(?:|%EE%80%A6)(?:|%EE%80%A7)(?:|%EE%80%B8)(?:|%EE%80%B9)(?:\\]|%5D)U2(?:\\[|%5B)(?:|%EE%89%9A)(?:|%EE%89%9B)(?:|%EE%89%AC)(?:|%EE%89%AD)(?:\\]|%5D)U3(?:\\[|%5B)(?:|%EE%93%BE)(?:|%EE%93%BF)(?:|%EE%94%80)(?:|%EE%94%8B)(?:|%EE%94%8C)(?:\\]|%5D)\\.js',
);
});
it('works with a pre-escaped suffix', () => {
const url = 'file:///foo';
const escapedRe = '\\/?($|index(\\.html)?)';
expect(urlToRegex(`${url}${escapedRe}`, [0, url.length])).to.equal(
'file:\\/\\/\\/foo\\/?($|index(\\.html)?)|\\/foo\\/?($|index(\\.html)?)',
);
});
it('works with a pre-escaped prefix', () => {
const path = 'foo';
const wildcardHostname = 'https?:\\/\\/[^\\/]+\\/';
const url = `${wildcardHostname}${path}`;
expect(urlToRegex(url, [wildcardHostname.length, url.length])).to.equal(
'https?:\\/\\/[^\\/]+\\/foo',
);
});
});

describe('urlToRegex - case insensitive', () => {
Expand Down
15 changes: 12 additions & 3 deletions src/common/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ export function urlToRegex(
) {
const patterns: string[] = [];

// Split out the portion of the path that has already been converted to a regex pattern
const rePrefix = aPath.slice(0, escapeReStart);
const reSuffix = aPath.slice(escapeReEnd);
const unescapedPath = aPath.slice(escapeReStart, escapeReEnd);

// aPath will often (always?) be provided as a file URI, or URL. Decode it
// --we'll reencode it as we go--and also create a match for its absolute
// path.
Expand All @@ -336,18 +341,22 @@ export function urlToRegex(
// - For case insensitive systems, we generate a regex like [fF][oO][oO]/(?:💩|%F0%9F%92%A9).[jJ][sS]
// - If we didn't de-encode it, the percent would be case-insensitized as
// well and we would not include the original character in the regex
for (const str of [decodeURI(aPath), fileUrlToAbsolutePath(aPath)]) {
for (let str of [decodeURI(unescapedPath), fileUrlToAbsolutePath(unescapedPath)]) {
if (!str) {
continue;
}

// Recombine the decoded portion of the string with the regex suffix/prefix before
// potentially converting the whole thing to a case insensitive pattern
str = `${rePrefix}${str}${reSuffix}`;

// Loop through each character of the string. Convert the char to a regex,
// creating a group, and then append that to the match.
const chars = new Set<string>();
let re = '';
for (let i = 0; i < str.length; i++) {
const char = str[i];
const escapeRegex = i >= escapeReStart && i < escapeReEnd;
const escapeRegex = i >= rePrefix.length && i < str.length - reSuffix.length;

if (isCaseSensitive) {
urlToRegexChar(char, chars, escapeRegex);
Expand All @@ -364,7 +373,7 @@ export function urlToRegex(
// fancy regex above), replace `file:///c:/` or simple `c:/` patterns with
// an insensitive drive letter.
patterns.push(
re.replace(
`${re}`.replace(
/^(file:\\\/\\\/\\\/)?([a-z]):/i,
(_, file = '', letter) => `${file}[${letter.toUpperCase()}${letter.toLowerCase()}]:`,
),
Expand Down
6 changes: 3 additions & 3 deletions src/targets/browser/browserPathResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,21 @@ describe('BrowserPathResolver', () => {
const e1 = 'http://localhost:1234/foo/bar(\\.html)?';
expect(
resolver().absolutePathToUrlRegexp(path.join(testFixturesDir, 'web', 'foo', 'bar.html')),
).to.equal(urlToRegex(e1, [0, e1.length - 10]));
).to.equal(urlToRegex(e1, [0, e1.length - 9]));

const e2 = 'http://localhost:1234/sibling/foo/bar(\\.html)?';
expect(
resolver().absolutePathToUrlRegexp(
path.join(testFixturesDir, 'sibling-dir', 'foo', 'bar.html'),
),
).to.equal(urlToRegex(e2, [0, e2.length - 10]));
).to.equal(urlToRegex(e2, [0, e2.length - 9]));
});

it('falls back if not in any webroot', () => {
const e = 'http://localhost:1234/../foo/bar(\\.html)?';
expect(
resolver().absolutePathToUrlRegexp(path.join(testFixturesDir, 'foo', 'bar.html')),
).to.equal(urlToRegex(e, [0, e.length - 10]));
).to.equal(urlToRegex(e, [0, e.length - 9]));
});

it('matches any path if no baseUrl is present', () => {
Expand Down