diff --git a/__tests__/no-bare-urls.test.ts b/__tests__/no-bare-urls.test.ts index e68082cf..f0acb67d 100644 --- a/__tests__/no-bare-urls.test.ts +++ b/__tests__/no-bare-urls.test.ts @@ -177,6 +177,22 @@ ruleTest({ `, }, + {// accounts for https://github.com/platers/obsidian-linter/issues/1030 + testName: 'Make sure that file URIs with three slashes are properly matched', + before: dedent` + # Untitled + + file:///C:/Untitled.md + `, + after: dedent` + # Untitled + + + `, + options: { + noBareURIs: true, + }, + }, ], }); diff --git a/src/rules/no-bare-urls.ts b/src/rules/no-bare-urls.ts index 6431ee96..fe39a00e 100644 --- a/src/rules/no-bare-urls.ts +++ b/src/rules/no-bare-urls.ts @@ -31,7 +31,6 @@ export default class NoBareUrls extends RuleBuilder { text = this.handleMatches(text, URLMatches, false); } - if (options.noBareURIs) { const URIMatches = text.match(simpleURIRegex); if (URIMatches) { diff --git a/src/utils/regex.ts b/src/utils/regex.ts index f6c0cc10..ebc5fcba 100644 --- a/src/utils/regex.ts +++ b/src/utils/regex.ts @@ -24,7 +24,7 @@ export const tableSeparator = /(\|? *:?-{1,}:? *\|?)(\| *:?-{1,}:? *\|?)*( |\t)* export const tableStartingPipe = /^(((>[ ]?)*)|([ ]{0,3}))\|/m; export const tableRow = /[^\n]*?\|[^\n]*?(\n|$)/m; // based on https://gist.github.com/skeller88/5eb73dc0090d4ff1249a -export const simpleURIRegex = /(([a-z\-0-9]+:)\/{2})([^\s/?#]*[^\s")'.?!/]|[/])?(([/?#][^\s")']*[^\s")'.?!])|[/])?/gi; +export const simpleURIRegex = /(([a-z\-0-9]+:)\/{2,3})([^\s/?#]*[^\s")'.?!/]|[/])?(([/?#][^\s")']*[^\s")'.?!])|[/])?/gi; // generated from https://github.com/spamscanner/url-regex-safe using strict: true, returnString: true, and re2: false as options export const urlRegex = /(?:(?:(?:[a-z]+:)?\/\/)|www\.)(?:localhost|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]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