Skip to content

Commit

Permalink
fix: treat all URI schemes as external (#945) (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Jul 8, 2022
1 parent 95a74e5 commit 1e9a7ac
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/client/theme-default/components/VPButton.vue
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue'
import { normalizeLink } from '../support/utils'
import { EXTERNAL_URL_RE } from '../../shared'
const props = defineProps<{
tag?: string
Expand All @@ -15,7 +16,7 @@ const classes = computed(() => [
props.theme ?? 'brand'
])
const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href))
const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href))
const component = computed(() => {
if (props.tag) {
Expand Down
3 changes: 2 additions & 1 deletion src/client/theme-default/components/VPLink.vue
Expand Up @@ -2,13 +2,14 @@
import { computed } from 'vue'
import { normalizeLink } from '../support/utils'
import VPIconExternalLink from './icons/VPIconExternalLink.vue'
import { EXTERNAL_URL_RE } from '../../shared'
const props = defineProps<{
href?: string
noIcon?: boolean
}>()
const isExternal = computed(() => props.href && /^[a-z]+:/i.test(props.href))
const isExternal = computed(() => props.href && EXTERNAL_URL_RE.test(props.href))
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions src/client/theme-default/support/utils.ts
@@ -1,15 +1,15 @@
import { ref } from 'vue'
import { withBase } from 'vitepress'
import { EXTERNAL_URL_RE } from '../../shared'

export const HASH_RE = /#.*$/
export const EXT_RE = /(index)?\.(md|html)$/
export const OUTBOUND_RE = /^[a-z]+:/i

const inBrowser = typeof window !== 'undefined'
const hashRef = ref(inBrowser ? location.hash : '')

export function isExternal(path: string): boolean {
return OUTBOUND_RE.test(path)
return EXTERNAL_URL_RE.test(path)
}

export function throttleAndDebounce(fn: () => void, delay: number): () => void {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/shared.ts
Expand Up @@ -10,7 +10,7 @@ export type {
PageDataPayload
} from '../../types/shared'

export const EXTERNAL_URL_RE = /^https?:/i
export const EXTERNAL_URL_RE = /^[a-z]+:/i
export const APPEARANCE_KEY = 'vitepress-theme-appearance'

// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/shared/tsconfig.json
@@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"lib": ["ESNext", "DOM"]
Expand Down

0 comments on commit 1e9a7ac

Please sign in to comment.