Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/vitepress
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2.1
Choose a base ref
...
head repository: vuejs/vitepress
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.2.2
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on May 21, 2024

  1. fix: dont escape ampersand twice in title

    brc-dd committed May 21, 2024
    1
    Copy the full SHA
    7ea3572 View commit details
  2. release: v1.2.2

    brc-dd committed May 21, 2024
    Copy the full SHA
    49dbfb4 View commit details
Showing with 26 additions and 29 deletions.
  1. +6 −0 CHANGELOG.md
  2. +1 −3 package.json
  3. +0 −16 pnpm-lock.yaml
  4. +1 −1 src/client/app/utils.ts
  5. +2 −1 src/client/index.ts
  6. +4 −4 src/node/build/render.ts
  7. +1 −4 src/node/markdown/plugins/restoreEntities.ts
  8. +11 −0 src/shared/shared.ts
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.2.2](https://github.com/vuejs/vitepress/compare/v1.2.1...v1.2.2) (2024-05-21)

### Bug Fixes

- dont escape ampersand twice in title ([7ea3572](https://github.com/vuejs/vitepress/commit/7ea357256c855ae0a9a142c14bbd5e7d344ef865))

## [1.2.1](https://github.com/vuejs/vitepress/compare/v1.2.0...v1.2.1) (2024-05-21)

### Bug Fixes
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vitepress",
"version": "1.2.1",
"version": "1.2.2",
"description": "Vite & Vue powered static site generator",
"keywords": [
"vite",
@@ -133,7 +133,6 @@
"@rollup/plugin-replace": "^5.0.5",
"@types/cross-spawn": "^6.0.6",
"@types/debug": "^4.1.12",
"@types/escape-html": "^1.0.4",
"@types/fs-extra": "^11.0.4",
"@types/lodash.template": "^4.5.3",
"@types/mark.js": "^8.11.12",
@@ -150,7 +149,6 @@
"cross-spawn": "^7.0.3",
"debug": "^4.3.4",
"esbuild": "^0.21.3",
"escape-html": "^1.0.3",
"execa": "^9.1.0",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
16 changes: 0 additions & 16 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/client/app/utils.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import {
type AsyncComponentLoader
} from 'vue'

export { inBrowser } from '../shared'
export { inBrowser, escapeHtml as _escapeHtml } from '../shared'

/**
* Join two paths by resolving the slash collision.
3 changes: 2 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ export {
onContentUpdated,
defineClientComponent,
withBase,
getScrollOffset
getScrollOffset,
_escapeHtml
} from './app/utils'

// components
8 changes: 4 additions & 4 deletions src/node/build/render.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { isBooleanAttr } from '@vue/shared'
import escape from 'escape-html'
import fs from 'fs-extra'
import path from 'path'
import { pathToFileURL } from 'url'
import { normalizePath, transformWithEsbuild, type Rollup } from 'vite'
import { version } from '../../../package.json'
import type { SiteConfig } from '../config'
import {
EXTERNAL_URL_RE,
createTitle,
escapeHtml,
mergeHead,
notFoundPageData,
resolveSiteDataByRoute,
@@ -17,7 +18,6 @@ import {
type PageData,
type SSGContext
} from '../shared'
import { version } from '../../../package.json'

export async function renderPage(
render: (path: string) => Promise<SSGContext>,
@@ -163,7 +163,7 @@ export async function renderPage(
? ''
: '<meta name="viewport" content="width=device-width,initial-scale=1">'
}
<title>${escape(title)}</title>
<title>${escapeHtml(title)}</title>
${
isDescriptionOverridden(head)
? ''
@@ -260,7 +260,7 @@ function renderAttrs(attrs: Record<string, string>): string {
return Object.keys(attrs)
.map((key) => {
if (isBooleanAttr(key)) return ` ${key}`
return ` ${key}="${escape(attrs[key] as string)}"`
return ` ${key}="${escapeHtml(attrs[key] as string)}"`
})
.join('')
}
5 changes: 1 addition & 4 deletions src/node/markdown/plugins/restoreEntities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type MarkdownIt from 'markdown-it'
import type StateCore from 'markdown-it/lib/rules_core/state_core.mjs'
import type Token from 'markdown-it/lib/token.mjs'
import { escapeHtml } from '../../shared'

export function restoreEntities(md: MarkdownIt): void {
md.core.ruler.at('text_join', text_join)
@@ -47,7 +48,3 @@ function getContent(token: Token): string {
? '&amp;'
: token.content
}

function escapeHtml(str: string): string {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
}
11 changes: 11 additions & 0 deletions src/shared/shared.ts
Original file line number Diff line number Diff line change
@@ -219,3 +219,14 @@ export function treatAsHtml(filename: string): boolean {
export function escapeRegExp(str: string) {
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
}

/**
* @internal
*/
export function escapeHtml(str: string): string {
return str
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/&(?![\w#]+;)/g, '&amp;')
}