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
6 changes: 6 additions & 0 deletions .changeset/quick-cloths-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tanstack/start-server-core': patch
'@tanstack/router-core': patch
---

chore: bump to h3 v2-rc.20
40 changes: 22 additions & 18 deletions e2e/react-start/basic-test-suite/src/special-characters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,31 +187,35 @@ test.describe('Unicode route rendering', () => {
})

test.describe('malformed paths', () => {
const malformedPathnames = [
'/specialChars/malformed/%E0%A4',
'/specialChars/malformed/%80',
'/specialChars/malformed/%FF',
]

test.use({
whitelistErrors: [
'Failed to load resource: the server responded with a status of 404',
'Failed to load resource: the server responded with a status of 400 (Bad Request)',
],
})

test('un-matched malformed paths should return not found on direct navigation', async ({
page,
}) => {
const res = await page.goto('/specialChars/malformed/%E0%A4')

await page.waitForLoadState(`load`)

// in spa mode this is caught and handled at server level
if (!isSpaMode) {
expect(res!.status()).toBe(404)

await expect(
page.getByTestId('default-not-found-component'),
).toBeInViewport()
} else {
expect(res!.status()).toBe(400)
}
})
for (const pathname of malformedPathnames) {
test(`un-matched malformed path "${pathname}" should return bad request on direct navigation`, async ({
page,
}) => {
const res = await page.goto(pathname)

await page.waitForLoadState(`load`)

// in spa mode this is caught and handled at server level
if (!isSpaMode) {
expect(res!.status()).toBe(400)
} else {
expect(res!.status()).toBe(400)
}
})
}

test('malformed path params should return not found on router link', async ({
page,
Expand Down
40 changes: 22 additions & 18 deletions e2e/solid-start/basic-test-suite/src/special-characters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,35 @@ test.describe('Unicode route rendering', () => {
})

test.describe('malformed paths', () => {
const malformedPathnames = [
'/specialChars/malformed/%E0%A4',
'/specialChars/malformed/%80',
'/specialChars/malformed/%FF',
]

test.use({
whitelistErrors: [
'Failed to load resource: the server responded with a status of 404',
'Failed to load resource: the server responded with a status of 400 (Bad Request)',
],
})

test('un-matched malformed paths should return not found on direct navigation', async ({
page,
}) => {
const res = await page.goto('/specialChars/malformed/%E0%A4')

await page.waitForLoadState(`load`)

// in spa mode this is caught and handled at server level
if (!isSpaMode) {
expect(res!.status()).toBe(404)

await expect(
page.getByTestId('default-not-found-component'),
).toBeInViewport()
} else {
expect(res!.status()).toBe(400)
}
})
for (const pathname of malformedPathnames) {
test(`un-matched malformed path "${pathname}" should return bad request on direct navigation`, async ({
page,
}) => {
const res = await page.goto(pathname)

await page.waitForLoadState(`load`)

// in spa mode this is caught and handled at server level
if (!isSpaMode) {
expect(res!.status()).toBe(400)
} else {
expect(res!.status()).toBe(400)
}
})
}

test('malformed path params should return not found on router link', async ({
page,
Expand Down
40 changes: 22 additions & 18 deletions e2e/vue-start/basic-test-suite/src/special-characters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,35 @@ test.describe('Unicode route rendering', () => {
})

test.describe('malformed paths', () => {
const malformedPathnames = [
'/specialChars/malformed/%E0%A4',
'/specialChars/malformed/%80',
'/specialChars/malformed/%FF',
]

test.use({
whitelistErrors: [
'Failed to load resource: the server responded with a status of 404',
'Failed to load resource: the server responded with a status of 400 (Bad Request)',
],
})

test('un-matched malformed paths should return not found on direct navigation', async ({
page,
}) => {
const res = await page.goto('/specialChars/malformed/%E0%A4')

await page.waitForLoadState(`load`)

// in spa mode this is caught and handled at server level
if (!isSpaMode) {
expect(res!.status()).toBe(404)

await expect(
page.getByTestId('default-not-found-component'),
).toBeInViewport()
} else {
expect(res!.status()).toBe(400)
}
})
for (const pathname of malformedPathnames) {
test(`un-matched malformed path "${pathname}" should return bad request on direct navigation`, async ({
page,
}) => {
const res = await page.goto(pathname)

await page.waitForLoadState(`load`)

// in spa mode this is caught and handled at server level
if (!isSpaMode) {
expect(res!.status()).toBe(400)
} else {
expect(res!.status()).toBe(400)
}
})
}

test('malformed path params should return not found on router link', async ({
page,
Expand Down
2 changes: 1 addition & 1 deletion packages/router-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
},
"dependencies": {
"@tanstack/history": "workspace:*",
"cookie-es": "^2.0.0",
"cookie-es": "^3.0.0",
"seroval": "^1.5.0",
"seroval-plugins": "^1.5.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/start-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
"@tanstack/router-core": "workspace:*",
"@tanstack/start-client-core": "workspace:*",
"@tanstack/start-storage-context": "workspace:*",
"h3-v2": "npm:h3@2.0.1-rc.16",
"h3-v2": "npm:h3@2.0.1-rc.20",
"seroval": "^1.5.0"
},
"devDependencies": {
"@standard-schema/spec": "^1.0.0",
"@tanstack/intent": "^0.0.14",
"cookie-es": "^2.0.0",
"cookie-es": "^3.0.0",
"fetchdts": "^0.1.6",
"vite": "*",
"@types/node": ">=20"
Expand Down
26 changes: 23 additions & 3 deletions packages/start-server-core/src/request-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ export function requestHandler<TRegister = unknown>(
handler: RequestHandler<TRegister>,
) {
return (request: Request, requestOpts: any): Promise<Response> | Response => {
const h3Event = new H3Event(request)
let h3Event: H3Event
try {
h3Event = new H3Event(request)
} catch (error) {
if (error instanceof URIError) {
return new Response(null, {
status: 400,
statusText: 'Bad Request',
})
}
throw error
}

const response = eventStorage.run({ h3Event }, () =>
handler(request, requestOpts),
Expand Down Expand Up @@ -284,7 +295,16 @@ export function setResponseStatus(code?: number, text?: string): void {
*/
export function getCookies(): Record<string, string> {
const event = getH3Event()
return h3_parseCookies(event)
const cookies = h3_parseCookies(event)
const definedCookies: Record<string, string> = Object.create(null)

for (const [name, value] of Object.entries(cookies)) {
if (value !== undefined) {
definedCookies[name] = value
}
}

return definedCookies
}

/**
Expand All @@ -296,7 +316,7 @@ export function getCookies(): Record<string, string> {
* ```
*/
export function getCookie(name: string): string | undefined {
return getCookies()[name] || undefined
return getCookies()[name]
}

/**
Expand Down
32 changes: 15 additions & 17 deletions pnpm-lock.yaml

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

Loading