Skip to content

Commit

Permalink
ignore hrefs with a scheme - fixes #2909
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Nov 25, 2021
1 parent c6b9ee4 commit b4d420f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/kit/src/utils/url.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const absolute = /^([a-z]+:)?\/?\//;
const scheme = /^[a-z]+:/;

/**
* @param {string} base
* @param {string} path
*/
export function resolve(base, path) {
if (scheme.test(path)) return path;

const base_match = absolute.exec(base);
const path_match = absolute.exec(path);

Expand Down
4 changes: 4 additions & 0 deletions packages/kit/src/utils/url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ test('resolves an absolute path', () => {
assert.equal(resolve('/a/b/c', 'https://example.com/foo'), 'https://example.com/foo');
});

test('handles schemes like tel: and mailto:', () => {
assert.equal(resolve('/a/b/c', 'mailto:hello@svelte.dev'), 'mailto:hello@svelte.dev');
});

test.run();

0 comments on commit b4d420f

Please sign in to comment.