Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inconsistent handling of non-ASCII base in resolveConfig and dev server #10247

Merged
merged 7 commits into from
Nov 7, 2022
39 changes: 20 additions & 19 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { parse as parseUrl, pathToFileURL } from 'node:url'
import { pathToFileURL } from 'node:url'
import { performance } from 'node:perf_hooks'
import { createRequire } from 'node:module'
import colors from 'picocolors'
Expand Down Expand Up @@ -813,33 +813,34 @@ export function resolveBaseUrl(
)
)
)
base = '/'
return '/'
}

// external URL
if (isExternalUrl(base)) {
if (!isBuild) {
// get base from full url during dev
const parsed = parseUrl(base)
base = parsed.pathname || '/'
}
} else {
// external URL flag
const isExternal = isExternalUrl(base)
// no leading slash warn
if (!isExternal && !base.startsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should start with a slash.`))
)
}
// no ending slash warn
if (!base.endsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should end with a slash.`))
)
}

// parse base when command is serve or base is not External URL
if (!isBuild || !isExternal) {
base = new URL(base, 'http://vitejs.dev').pathname
// ensure leading slash
if (!base.startsWith('/')) {
logger.warn(
colors.yellow(
colors.bold(`(!) "base" option should start with a slash.`)
)
)
base = '/' + base
}
}

// ensure ending slash
if (!base.endsWith('/')) {
logger.warn(
colors.yellow(colors.bold(`(!) "base" option should end with a slash.`))
)
base += '/'
}

Expand Down