fix: wrong recognition of non-html extension leads to route error (#3218)

pull/3221/head
烽宁 1 year ago committed by GitHub
parent 672e4946ac
commit c4abc950af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -100,6 +100,7 @@
"focus-trap": "^7.5.4", "focus-trap": "^7.5.4",
"mark.js": "8.11.1", "mark.js": "8.11.1",
"minisearch": "^6.2.0", "minisearch": "^6.2.0",
"mrmime": "^1.0.1",
"shiki": "^0.14.5", "shiki": "^0.14.5",
"vite": "^5.0.0", "vite": "^5.0.0",
"vue": "^3.3.8" "vue": "^3.3.8"

@ -1,9 +1,5 @@
lockfileVersion: '6.0' lockfileVersion: '6.0'
settings:
autoInstallPeers: false
excludeLinksFromLockfile: false
overrides: overrides:
ora>string-width: ^5 ora>string-width: ^5
@ -41,6 +37,9 @@ importers:
minisearch: minisearch:
specifier: ^6.2.0 specifier: ^6.2.0
version: 6.2.0 version: 6.2.0
mrmime:
specifier: ^1.0.1
version: 1.0.1
shiki: shiki:
specifier: ^0.14.5 specifier: ^0.14.5
version: 0.14.5 version: 0.14.5
@ -3325,7 +3324,6 @@ packages:
/mrmime@1.0.1: /mrmime@1.0.1:
resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==} resolution: {integrity: sha512-hzzEagAgDyoU1Q6yg5uI+AorQgdvMCur3FcKf7NhMKWsaYg+RnbTyHRa/9IlLF9rf455MOCtcqqrQQ83pPP7Uw==}
engines: {node: '>=10'} engines: {node: '>=10'}
dev: true
/ms@2.0.0: /ms@2.0.0:
resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==}
@ -4717,3 +4715,7 @@ packages:
resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==}
engines: {node: '>=12.20'} engines: {node: '>=12.20'}
dev: true dev: true
settings:
autoInstallPeers: false
excludeLinksFromLockfile: false

@ -1,5 +1,6 @@
import { reactive, inject, markRaw, nextTick, readonly } from 'vue' import { reactive, inject, markRaw, nextTick, readonly } from 'vue'
import type { Component, InjectionKey } from 'vue' import type { Component, InjectionKey } from 'vue'
import { lookup } from 'mrmime'
import { notFoundPageData } from '../shared' import { notFoundPageData } from '../shared'
import type { PageData, PageDataPayload, Awaitable } from '../shared' import type { PageData, PageDataPayload, Awaitable } from '../shared'
import { inBrowser, withBase } from './utils' import { inBrowser, withBase } from './utils'
@ -181,7 +182,6 @@ export function createRouter(
link.baseURI link.baseURI
) )
const currentUrl = window.location const currentUrl = window.location
const extMatch = pathname.match(/\.\w+$/)
// only intercept inbound links // only intercept inbound links
if ( if (
!e.ctrlKey && !e.ctrlKey &&
@ -191,7 +191,9 @@ export function createRouter(
!target && !target &&
origin === currentUrl.origin && origin === currentUrl.origin &&
// don't intercept if non-html extension is present // don't intercept if non-html extension is present
!(extMatch && extMatch[0] !== '.html') !(siteDataRef.value.cleanUrls
? lookup(pathname)
: lookup(pathname) !== 'text/html')
) { ) {
e.preventDefault() e.preventDefault()
if ( if (

@ -1,4 +1,5 @@
import { withBase } from 'vitepress' import { withBase } from 'vitepress'
import { lookup } from 'mrmime'
import { useData } from '../composables/data' import { useData } from '../composables/data'
import { isExternal } from '../../shared' import { isExternal } from '../../shared'
@ -27,7 +28,7 @@ export function normalizeLink(url: string): string {
isExternal(url) || isExternal(url) ||
url.startsWith('#') || url.startsWith('#') ||
!protocol.startsWith('http') || !protocol.startsWith('http') ||
/\.(?!html|md)\w+($|\?)/i.test(url) (/\.(?!html|md)\w+($|\?)/i.test(url) && lookup(url))
) )
return url return url

Loading…
Cancel
Save