Skip to content

Commit

Permalink
fix: wrong recognition of non-html extension leads to route error (#3218
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zonemeen committed Nov 18, 2023
1 parent 672e494 commit c4abc95
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -100,6 +100,7 @@
"focus-trap": "^7.5.4",
"mark.js": "8.11.1",
"minisearch": "^6.2.0",
"mrmime": "^1.0.1",
"shiki": "^0.14.5",
"vite": "^5.0.0",
"vue": "^3.3.8"
Expand Down
12 changes: 7 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/client/app/router.ts
@@ -1,5 +1,6 @@
import { reactive, inject, markRaw, nextTick, readonly } from 'vue'
import type { Component, InjectionKey } from 'vue'
import { lookup } from 'mrmime'
import { notFoundPageData } from '../shared'
import type { PageData, PageDataPayload, Awaitable } from '../shared'
import { inBrowser, withBase } from './utils'
Expand Down Expand Up @@ -181,7 +182,6 @@ export function createRouter(
link.baseURI
)
const currentUrl = window.location
const extMatch = pathname.match(/\.\w+$/)
// only intercept inbound links
if (
!e.ctrlKey &&
Expand All @@ -191,7 +191,9 @@ export function createRouter(
!target &&
origin === currentUrl.origin &&
// don't intercept if non-html extension is present
!(extMatch && extMatch[0] !== '.html')
!(siteDataRef.value.cleanUrls
? lookup(pathname)
: lookup(pathname) !== 'text/html')
) {
e.preventDefault()
if (
Expand Down
3 changes: 2 additions & 1 deletion src/client/theme-default/support/utils.ts
@@ -1,4 +1,5 @@
import { withBase } from 'vitepress'
import { lookup } from 'mrmime'
import { useData } from '../composables/data'
import { isExternal } from '../../shared'

Expand Down Expand Up @@ -27,7 +28,7 @@ export function normalizeLink(url: string): string {
isExternal(url) ||
url.startsWith('#') ||
!protocol.startsWith('http') ||
/\.(?!html|md)\w+($|\?)/i.test(url)
(/\.(?!html|md)\w+($|\?)/i.test(url) && lookup(url))
)
return url

Expand Down

0 comments on commit c4abc95

Please sign in to comment.