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

ignore mailto: links etc #2915

Merged
merged 2 commits into from Nov 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-numbers-promise.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Ignore mailto: and tel: links
3 changes: 3 additions & 0 deletions packages/kit/src/utils/url.js
@@ -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
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();