Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function joinUrlSegments(a: string, b: string): string {
if (!a || !b) {
return a || b || ''
}
if (a[a.length - 1] === '/') {
if (a.endsWith('/')) {
a = a.substring(0, a.length - 1)
}
if (b[0] !== '/') {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ export async function formatPostcssSourceMap(
const cleanSource = cleanUrl(decodeURIComponent(source))

// postcss virtual files
if (cleanSource[0] === '<' && cleanSource[cleanSource.length - 1] === '>') {
if (cleanSource[0] === '<' && cleanSource.endsWith('>')) {
return `\0${cleanSource}`
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
let url = name
if (!url) {
const rawUrl = code.slice(start, end)
if (rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`)
if (rawUrl[0] === `"` && rawUrl.endsWith(`"`))
url = rawUrl.slice(1, -1)
}
if (!url) continue
Expand Down Expand Up @@ -516,7 +516,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
let url = name
if (!url) {
const rawUrl = code.slice(start, end)
if (rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`)
if (rawUrl[0] === `"` && rawUrl.endsWith(`"`))
url = rawUrl.slice(1, -1)
}
const deps = new Set<string>()
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ export function tryNodeResolve(
importer &&
path.isAbsolute(importer) &&
// css processing appends `*` for importer
(importer[importer.length - 1] === '*' || fs.existsSync(cleanUrl(importer)))
(importer.endsWith('*') || fs.existsSync(cleanUrl(importer)))
) {
basedir = path.dirname(importer)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/htmlFallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function htmlFallbackMiddleware(
}
}
// trailing slash should check for fallback index.html
else if (pathname[pathname.length - 1] === '/') {
else if (pathname.endsWith('/')) {
const filePath = path.join(root, pathname, 'index.html')
if (fs.existsSync(filePath)) {
const newUrl = url + 'index.html'
Expand Down
7 changes: 2 additions & 5 deletions packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function serveStaticMiddleware(
// also skip internal requests `/@fs/ /@vite-client` etc...
const cleanedUrl = cleanUrl(req.url!)
if (
cleanedUrl[cleanedUrl.length - 1] === '/' ||
cleanedUrl.endsWith('/') ||
path.extname(cleanedUrl) === '.html' ||
isInternalRequest(req.url!) ||
// skip url starting with // as these will be interpreted as
Expand Down Expand Up @@ -151,10 +151,7 @@ export function serveStaticMiddleware(

const resolvedPathname = redirectedPathname || pathname
let fileUrl = path.resolve(dir, removeLeadingSlash(resolvedPathname))
if (
resolvedPathname[resolvedPathname.length - 1] === '/' &&
fileUrl[fileUrl.length - 1] !== '/'
) {
if (resolvedPathname.endsWith('/') && fileUrl[fileUrl.length - 1] !== '/') {
fileUrl = withTrailingSlash(fileUrl)
}
if (!ensureServingAccess(fileUrl, server, res, next)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@ function normalizeSingleAlias({
}: Alias): Alias {
if (
typeof find === 'string' &&
find[find.length - 1] === '/' &&
replacement[replacement.length - 1] === '/'
find.endsWith('/') &&
replacement.endsWith('/')
) {
find = find.slice(0, find.length - 1)
replacement = replacement.slice(0, replacement.length - 1)
Expand Down Expand Up @@ -1458,7 +1458,7 @@ export function joinUrlSegments(a: string, b: string): string {
if (!a || !b) {
return a || b || ''
}
if (a[a.length - 1] === '/') {
if (a.endsWith('/')) {
a = a.substring(0, a.length - 1)
}
if (b[0] !== '/') {
Expand Down
2 changes: 1 addition & 1 deletion playground/fs-serve/root/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h2>Denied</h2>
if (!a || !b) {
return a || b || ''
}
if (a[a.length - 1] === '/') {
if (a.endsWith('/')) {
a = a.substring(0, a.length - 1)
}
if (b[0] !== '/') {
Expand Down