Skip to content

Commit 27573f4

Browse files
authored
fix: Not reporting mailto: and other unusual schema addresses in no-nmavigation-without-resolve (and its deprecated versions) (#1313)
1 parent 8bd6198 commit 27573f4

19 files changed

+41
-4
lines changed

.changeset/six-pugs-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix: Not reporting mailto: and other unusual schema addresses in no-nmavigation-without-resolve (and its deprecated versions)

packages/eslint-plugin-svelte/src/rules/no-goto-without-base.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ function checkTemplateLiteral(
7171
}
7272

7373
function checkLiteral(context: RuleContext, path: TSESTree.Literal): void {
74-
const absolutePathRegex = /^(?:[+a-z]+:)?\/\//i;
75-
if (!absolutePathRegex.test(path.value?.toString() ?? '')) {
74+
if (!/^[+a-z]*:/i.test(path.value?.toString() ?? '')) {
7675
context.report({ loc: path.loc, messageId: 'isNotPrefixedWithBasePath' });
7776
}
7877
}

packages/eslint-plugin-svelte/src/rules/no-navigation-without-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ function templateLiteralIsAbsolute(url: TSESTree.TemplateLiteral): boolean {
268268
}
269269

270270
function urlValueIsAbsolute(url: string): boolean {
271-
return url.includes('://');
271+
return /^[+a-z]*:/i.test(url);
272272
}
273273

274274
function expressionIsFragment(url: AST.SvelteLiteral | TSESTree.Expression): boolean {

packages/eslint-plugin-svelte/src/rules/no-navigation-without-resolve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function templateLiteralIsAbsolute(url: TSESTree.TemplateLiteral): boolean {
282282
}
283283

284284
function urlValueIsAbsolute(url: string): boolean {
285-
return url.includes('://');
285+
return /^[+a-z]*:/i.test(url);
286286
}
287287

288288
function expressionIsFragment(url: AST.SvelteLiteral | TSESTree.Expression): boolean {

packages/eslint-plugin-svelte/tests/fixtures/rules/no-goto-without-base/invalid/no-base01-errors.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
line: 4
33
column: 7
44
suggestions: null
5+
- message: Found a goto() call with a url that isn't prefixed with the base path.
6+
line: 5
7+
column: 7
8+
suggestions: null

packages/eslint-plugin-svelte/tests/fixtures/rules/no-goto-without-base/invalid/no-base01-input.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
import { goto } from '$app/navigation';
33
44
goto('/foo');
5+
goto('/user:42');
56
</script>

packages/eslint-plugin-svelte/tests/fixtures/rules/no-goto-without-base/valid/absolute-uri01-input.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
44
goto('http://localhost/foo/');
55
goto('https://localhost/foo/');
6+
goto('mailto:user@example.com');
7+
goto('tel:+123456789');
68
</script>

packages/eslint-plugin-svelte/tests/fixtures/rules/no-navigation-without-base/invalid/link-no-base01-errors.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
line: 7
1515
column: 9
1616
suggestions: null
17+
- message: Found a link with a url that isn't prefixed with the base path.
18+
line: 8
19+
column: 9
20+
suggestions: null

packages/eslint-plugin-svelte/tests/fixtures/rules/no-navigation-without-base/invalid/link-no-base01-input.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
<a href={'/foo'}>Click me!</a>
66
<a href={'/' + 'foo'}>Click me!</a>
77
<a href={value}>Click me!</a>
8+
<a href={'/user:42'}>Click me!</a>

packages/eslint-plugin-svelte/tests/fixtures/rules/no-navigation-without-base/invalid/link-with-fragment01-errors.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
line: 7
1515
column: 9
1616
suggestions: null
17+
- message: Found a link with a url that isn't prefixed with the base path.
18+
line: 8
19+
column: 9
20+
suggestions: null

0 commit comments

Comments
 (0)