Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,9 @@ describe('resolveConfig', () => {
}
})

test('support escaped input', async () => {
// On Windows, backslash is the path separator, so glob characters cannot
// be escaped with a backslash in input paths.
test.skipIf(isWindows)('support escaped input', async () => {
const cases: {
name: string
input: UserConfig['input']
Expand Down Expand Up @@ -1314,6 +1316,59 @@ describe('resolveConfig', () => {
}
})

// https://github.com/vitejs/vite/issues/23383
test('preserves Windows input paths with glob-special segment names', async () => {
const cases: {
name: string
input: UserConfig['input']
expected: UserConfig['input']
}[] = [
...(isWindows
? [
{
name: 'segment starting with @',
input: 'D:\\desk\\test\\@src\\whatever.html',
expected: 'D:\\desk\\test\\@src\\whatever.html',
},
{
name: 'segment starting with !',
input: 'D:\\desk\\test\\!notes\\page.html',
expected: 'D:\\desk\\test\\!notes\\page.html',
},
{
name: 'segment starting with +',
input: 'D:\\desk\\test\\+draft\\page.html',
expected: 'D:\\desk\\test\\+draft\\page.html',
},
{
name: 'segment starting with (',
input: 'D:\\desk\\test\\(draft)\\page.html',
expected: 'D:\\desk\\test\\(draft)\\page.html',
},
{
name: 'segment starting with [',
input: 'D:\\desk\\test\\[id]\\page.html',
expected: 'D:\\desk\\test\\[id]\\page.html',
},
{
name: 'relative path',
input: 'test\\@src\\whatever.html',
expected: 'test\\@src\\whatever.html',
},
]
: []),
]

for (const { name, input, expected } of cases) {
await expect(
resolveConfig({ input }, 'serve'),
name,
).resolves.toMatchObject({
input: expected,
})
}
})

test('is used as the default for build.lib.entry when entry is omitted', async () => {
const config = await resolveConfig(
{
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
createImportMetaResolver,
importMetaResolveWithCustomHookString,
} from '../module-runner/importMetaResolver'
import { withTrailingSlash } from '../shared/utils'
import { isWindows, withTrailingSlash } from '../shared/utils'
import type { AnymatchFn } from '../types/anymatch'
import type { HtmlAssetSource } from './assetSource'
import { PartialEnvironment } from './baseEnvironment'
Expand Down Expand Up @@ -955,6 +955,11 @@ function unescapeGlobCharacters(value: string): string {
`so the ${JSON.stringify(value)} is not allowed. Please escape them with a backslash (\\)`,
)
}
// On Windows, backslash is the path separator, so it must not be treated
// as an escape character for glob characters (#23383).
if (isWindows) {
return value
}
// unescape glob characters
return value.replace(escapedGlobCharactersRE, '$1')
}
Expand Down
Loading