Skip to content

Commit

Permalink
ignore mailto: links etc (#2915)
Browse files Browse the repository at this point in the history
* ignore hrefs with a scheme - fixes #2909

* changeset
  • Loading branch information
Rich-Harris authored Nov 25, 2021
1 parent cf3a8b5 commit 3365f0b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-numbers-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Ignore mailto: and tel: links
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 3365f0b

Please sign in to comment.