0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-31 23:31:30 -05:00

Fix error overlay display on malformed uri (#9548)

This commit is contained in:
Bjorn Lu 2023-12-29 22:52:43 +07:00 committed by GitHub
parent af59b83162
commit 8049f0cd91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fixes error overlay display on URI malformed error

View file

@ -111,7 +111,7 @@ export interface AstroErrorPayload {
hint?: string;
docslink?: string;
highlightedCode?: string;
loc: {
loc?: {
file?: string;
line?: number;
column?: number;

View file

@ -631,7 +631,7 @@ class ErrorOverlay extends HTMLElement {
}
const code = this.root.querySelector<HTMLElement>('#code');
if (code && err.loc.file) {
if (code && err.loc?.file) {
code.style.display = 'block';
const codeHeader = code.querySelector<HTMLHeadingElement>('#code header');
const codeContent = code.querySelector<HTMLDivElement>('#code-content');
@ -670,7 +670,7 @@ class ErrorOverlay extends HTMLElement {
}
// Add an empty line below the error line so we can show a caret under the error
if (err.loc.column) {
if (err.loc?.column) {
errorLine.insertAdjacentHTML(
'afterend',
`\n<span class="line error-caret"><span style="padding-left:${

View file

@ -20,7 +20,13 @@ export function baseMiddleware(
return function devBaseMiddleware(req, res, next) {
const url = req.url!;
const pathname = decodeURI(new URL(url, 'http://localhost').pathname);
let pathname: string;
try {
pathname = decodeURI(new URL(url, 'http://localhost').pathname);
} catch (e) {
/* malform uri */
return next(e);
}
if (pathname.startsWith(devRoot)) {
req.url = url.replace(devRoot, devRootReplacement);