Skip to content

Commit 8049f0c

Browse files
authoredDec 29, 2023
Fix error overlay display on malformed uri (#9548)
1 parent af59b83 commit 8049f0c

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed
 

‎.changeset/great-beans-check.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Fixes error overlay display on URI malformed error

‎packages/astro/src/core/errors/dev/vite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export interface AstroErrorPayload {
111111
hint?: string;
112112
docslink?: string;
113113
highlightedCode?: string;
114-
loc: {
114+
loc?: {
115115
file?: string;
116116
line?: number;
117117
column?: number;

‎packages/astro/src/core/errors/overlay.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class ErrorOverlay extends HTMLElement {
631631
}
632632

633633
const code = this.root.querySelector<HTMLElement>('#code');
634-
if (code && err.loc.file) {
634+
if (code && err.loc?.file) {
635635
code.style.display = 'block';
636636
const codeHeader = code.querySelector<HTMLHeadingElement>('#code header');
637637
const codeContent = code.querySelector<HTMLDivElement>('#code-content');
@@ -670,7 +670,7 @@ class ErrorOverlay extends HTMLElement {
670670
}
671671

672672
// Add an empty line below the error line so we can show a caret under the error
673-
if (err.loc.column) {
673+
if (err.loc?.column) {
674674
errorLine.insertAdjacentHTML(
675675
'afterend',
676676
`\n<span class="line error-caret"><span style="padding-left:${

‎packages/astro/src/vite-plugin-astro-server/base.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ export function baseMiddleware(
2020
return function devBaseMiddleware(req, res, next) {
2121
const url = req.url!;
2222

23-
const pathname = decodeURI(new URL(url, 'http://localhost').pathname);
23+
let pathname: string;
24+
try {
25+
pathname = decodeURI(new URL(url, 'http://localhost').pathname);
26+
} catch (e) {
27+
/* malform uri */
28+
return next(e);
29+
}
2430

2531
if (pathname.startsWith(devRoot)) {
2632
req.url = url.replace(devRoot, devRootReplacement);

0 commit comments

Comments
 (0)
Please sign in to comment.