From 04026a3861660bed32ffc3aa8f405f581b07a8e9 Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Wed, 16 Mar 2022 12:44:05 +0300 Subject: [PATCH] refactor: use `ufo.hasProtocol` to detect external link (#3686) --- packages/bridge/package.json | 2 +- packages/nitro/package.json | 2 +- packages/nuxt3/package.json | 2 +- .../nuxt3/src/app/components/nuxt-link.ts | 7 +++---- packages/schema/package.json | 2 +- packages/vite/package.json | 2 +- packages/webpack/package.json | 2 +- yarn.lock | 19 +++++++++++++------ 8 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/bridge/package.json b/packages/bridge/package.json index b53b3e25d0..9a23b77bca 100644 --- a/packages/bridge/package.json +++ b/packages/bridge/package.json @@ -55,7 +55,7 @@ "postcss-url": "^10.1.3", "scule": "^0.2.1", "semver": "^7.3.5", - "ufo": "^0.7.11", + "ufo": "^0.8.0", "unplugin": "^0.5.2", "unplugin-vue2-script-setup": "^0.10.0", "untyped": "^0.4.3", diff --git a/packages/nitro/package.json b/packages/nitro/package.json index fbc6e653b6..24a7f604c7 100644 --- a/packages/nitro/package.json +++ b/packages/nitro/package.json @@ -66,7 +66,7 @@ "serve-static": "^1.14.2", "std-env": "^3.0.1", "table": "^6.8.0", - "ufo": "^0.7.11", + "ufo": "^0.8.0", "unenv": "^0.4.3", "unstorage": "^0.3.3", "vue-bundle-renderer": "^0.3.5", diff --git a/packages/nuxt3/package.json b/packages/nuxt3/package.json index 9589b2d525..326e153a93 100644 --- a/packages/nuxt3/package.json +++ b/packages/nuxt3/package.json @@ -57,7 +57,7 @@ "ohmyfetch": "^0.4.15", "pathe": "^0.2.0", "scule": "^0.2.1", - "ufo": "^0.7.11", + "ufo": "^0.8.0", "unimport": "^0.1.0", "unplugin": "^0.5.2", "untyped": "^0.4.3", diff --git a/packages/nuxt3/src/app/components/nuxt-link.ts b/packages/nuxt3/src/app/components/nuxt-link.ts index 53cc5db063..e5ea01958c 100644 --- a/packages/nuxt3/src/app/components/nuxt-link.ts +++ b/packages/nuxt3/src/app/components/nuxt-link.ts @@ -1,5 +1,6 @@ import { defineComponent, h, resolveComponent, PropType, computed, DefineComponent } from 'vue' import { RouteLocationRaw, Router } from 'vue-router' +import { hasProtocol } from 'ufo' import { useRouter } from '#app' @@ -140,10 +141,8 @@ export function defineNuxtLink (options: NuxtLinkOptions) { return false } - // Directly check if `to` is an external URL with Regex - // Regex101 expression: {@link https://regex101.com/r/1y7iod/1} - // TODO: Use `ufo.hasProtocol` when issue fixed https://github.com/unjs/ufo/issues/45 - return !/^\/(?!\/)/.test(to.value) + // Directly check if `to` is an external URL by checking protocol + return hasProtocol(to.value, true) }) return () => { diff --git a/packages/schema/package.json b/packages/schema/package.json index 3b98f1eb72..3f2c2cbec6 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -27,7 +27,7 @@ "postcss-import-resolver": "^2.0.0", "scule": "^0.2.1", "std-env": "^3.0.1", - "ufo": "^0.7.11", + "ufo": "^0.8.0", "unimport": "^0.1.0" }, "engines": { diff --git a/packages/vite/package.json b/packages/vite/package.json index 34539e0a77..47e9dc74d8 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -41,7 +41,7 @@ "postcss-url": "^10.1.3", "rollup": "^2.70.1", "rollup-plugin-visualizer": "^5.6.0", - "ufo": "^0.7.11", + "ufo": "^0.8.0", "unplugin": "^0.5.2", "vite": "^2.8.6", "vite-node": "^0.6.1" diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 3854477016..457a3804f3 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -41,7 +41,7 @@ "postcss-url": "^10.1.3", "style-resources-loader": "^1.5.0", "time-fix-plugin": "^2.0.7", - "ufo": "^0.7.11", + "ufo": "^0.8.0", "unplugin": "^0.5.2", "url-loader": "^4.1.1", "vue-loader": "^17.0.0", diff --git a/yarn.lock b/yarn.lock index 07714c7c47..11f4598e32 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2745,7 +2745,7 @@ __metadata: postcss-url: ^10.1.3 scule: ^0.2.1 semver: ^7.3.5 - ufo: ^0.7.11 + ufo: ^0.8.0 unbuild: latest unplugin: ^0.5.2 unplugin-vue2-script-setup: ^0.10.0 @@ -3153,7 +3153,7 @@ __metadata: serve-static: ^1.14.2 std-env: ^3.0.1 table: ^6.8.0 - ufo: ^0.7.11 + ufo: ^0.8.0 unbuild: latest unenv: ^0.4.3 unstorage: ^0.3.3 @@ -3206,7 +3206,7 @@ __metadata: postcss-import-resolver: ^2.0.0 scule: ^0.2.1 std-env: ^3.0.1 - ufo: ^0.7.11 + ufo: ^0.8.0 unbuild: latest unimport: ^0.1.0 languageName: unknown @@ -3449,7 +3449,7 @@ __metadata: postcss-url: ^10.1.3 rollup: ^2.70.1 rollup-plugin-visualizer: ^5.6.0 - ufo: ^0.7.11 + ufo: ^0.8.0 unbuild: latest unplugin: ^0.5.2 vite: ^2.8.6 @@ -3569,7 +3569,7 @@ __metadata: postcss-url: ^10.1.3 style-resources-loader: ^1.5.0 time-fix-plugin: ^2.0.7 - ufo: ^0.7.11 + ufo: ^0.8.0 unbuild: latest unplugin: ^0.5.2 url-loader: ^4.1.1 @@ -15801,7 +15801,7 @@ __metadata: ohmyfetch: ^0.4.15 pathe: ^0.2.0 scule: ^0.2.1 - ufo: ^0.7.11 + ufo: ^0.8.0 unbuild: latest unimport: ^0.1.0 unplugin: ^0.5.2 @@ -21314,6 +21314,13 @@ __metadata: languageName: node linkType: hard +"ufo@npm:^0.8.0": + version: 0.8.0 + resolution: "ufo@npm:0.8.0" + checksum: cab38504a4caf316a9b24d187d24400c403599d563c260fbdad5e61371ed0be756edb8d1e0b322f37a4c8893e7496e47ea193f1cb039c343e6f6924a95ccadfe + languageName: node + linkType: hard + "uglify-js@npm:^3.1.4, uglify-js@npm:^3.5.1": version: 3.15.2 resolution: "uglify-js@npm:3.15.2"