From c4f31be3ae73a59ee7acbf3ef025fdf182245a38 Mon Sep 17 00:00:00 2001 From: velzie Date: Mon, 15 Jul 2024 18:20:50 -0400 Subject: [PATCH] fix rewriter crashes (this code is bad) --- src/shared/rewriters/html.ts | 3 ++- src/worker/index.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/rewriters/html.ts b/src/shared/rewriters/html.ts index 8a1760c..2417ef2 100644 --- a/src/shared/rewriters/html.ts +++ b/src/shared/rewriters/html.ts @@ -81,7 +81,8 @@ function traverseParsedHtml(node, origin?: URL) { node.attribs.content.includes("url") ) { const contentArray = node.attribs.content.split("url="); - contentArray[1] = encodeUrl(contentArray[1].trim(), origin); + if (contentArray[1]) + contentArray[1] = encodeUrl(contentArray[1].trim(), origin); node.attribs.content = contentArray.join("url="); } } diff --git a/src/worker/index.ts b/src/worker/index.ts index 5d5a301..97eff42 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -70,6 +70,7 @@ self.ScramjetServiceWorker = class ScramjetServiceWorker { let cookieParsed = cookie.split(";").map((x) => x.trim().split("=")); let [key, value] = cookieParsed.shift(); + if (!value) continue; value = value.replace("\"", ""); const hostArg = cookieParsed.find((x) => x[0] === "Domain");