diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4da7059 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Jamison Dance + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/package.json b/package.json index 34cdb9c..51f9fd1 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "the-internet", "version": "1.0.0", "private": true, + "license": "MIT", "scripts": { "dev": "wrangler dev", "deploy": "wrangler deploy", diff --git a/src/rewriter.ts b/src/rewriter.ts index 4e02077..8e46797 100644 --- a/src/rewriter.ts +++ b/src/rewriter.ts @@ -5,13 +5,12 @@ import { uppercaseScript } from "./uppercase-script"; const ENTITY_PATTERN = /(&(?:#(?:x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z][a-zA-Z0-9]*);)/g; function uppercasePreservingEntities(raw: string): string { - return raw.split(ENTITY_PATTERN) + return raw + .split(ENTITY_PATTERN) .map((part, i) => (i % 2 === 0 ? part.toUpperCase() : part)) .join(""); } - - class SimpleTextUppercaser implements HTMLRewriterElementContentHandlers { text(text: Text) { if (text.text) { diff --git a/src/utils.test.ts b/src/utils.test.ts index 916c680..e479254 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -21,13 +21,11 @@ describe("decodeHTMLEntities", () => { }); it("decodes named entities", () => { - expect(decodeHTMLEntities("a&b<c>d"e'f")).toBe('a&bd"e\'f'); + expect(decodeHTMLEntities("a&b<c>d"e'f")).toBe("a&bd\"e'f"); }); it("passes through strings with no entities", () => { - expect(decodeHTMLEntities("https://example.com/path?q=1")).toBe( - "https://example.com/path?q=1", - ); + expect(decodeHTMLEntities("https://example.com/path?q=1")).toBe("https://example.com/path?q=1"); }); it("handles ' (apostrophe, common in HN)", () => { @@ -68,15 +66,11 @@ describe("resolveAndProxy with HN-encoded URLs", () => { }); it("still resolves normal absolute URLs", () => { - expect(resolveAndProxy("https://example.com", HN_BASE)).toBe( - "/browse/https://example.com/", - ); + expect(resolveAndProxy("https://example.com", HN_BASE)).toBe("/browse/https://example.com/"); }); it("passes through data: URIs", () => { - expect(resolveAndProxy("data:image/png;base64,abc", HN_BASE)).toBe( - "data:image/png;base64,abc", - ); + expect(resolveAndProxy("data:image/png;base64,abc", HN_BASE)).toBe("data:image/png;base64,abc"); }); it("passes through javascript: URIs", () => { diff --git a/src/utils.ts b/src/utils.ts index 1db3da6..783cb9d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,11 @@ // HTMLRewriter getAttribute() returns raw HTML — entities aren't decoded. // HN (and others) encode slashes as / which breaks URL parsing. const NAMED_ENTITIES: Record = { - "&": "&", "<": "<", ">": ">", """: '"', "'": "'", + "&": "&", + "<": "<", + ">": ">", + """: '"', + "'": "'", }; export function decodeHTMLEntities(s: string): string { @@ -58,7 +62,6 @@ export function stripHeaders(headers: Headers): Headers { return stripped; } - export function forwardHeaders(request: Request): HeadersInit { const forwarded: Record = {}; const pass = ["user-agent", "accept", "accept-language", "accept-encoding", "cookie", "referer"];