From c2e71a45b559ad581e6a80dd321a051e20c19579 Mon Sep 17 00:00:00 2001 From: Freeman Date: Sat, 16 Mar 2024 17:03:37 +0000 Subject: [PATCH] Fixed Missing HTML Instructions #32 --- package.json | 2 +- src/handlers/html.test.ts | 13 +++++++++++++ src/handlers/html.ts | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 81b61e7..a56e390 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-css-obfuscator", - "version": "2.2.14", + "version": "2.2.15", "description": "A package deeply inspired by PostCSS-Obfuscator but for Next.js.", "main": "dist/index.js", "type": "commonjs", diff --git a/src/handlers/html.test.ts b/src/handlers/html.test.ts index b4506de..273fcae 100644 --- a/src/handlers/html.test.ts +++ b/src/handlers/html.test.ts @@ -201,4 +201,17 @@ describe("obfuscateHtmlClassNames", () => { expect(result.obfuscatedContent).toEqual(`
`); expect(result.usedKeys).to.deep.equal([".foo", ".bar", ".baz"]); }); + + it("should handle HTML instruction", () => { + // Arrange + const html = `
`; + const selectorConversion: SelectorConversion = { ".foo": ".a" }; + + // Act + const result = obfuscateHtmlClassNames({ html, selectorConversion }); + + // Assert + expect(result.obfuscatedContent).toEqual(`
`); + expect(result.usedKeys).to.deep.equal([".foo"]); + }); }); \ No newline at end of file diff --git a/src/handlers/html.ts b/src/handlers/html.ts index 1ec4c94..accd2d6 100644 --- a/src/handlers/html.ts +++ b/src/handlers/html.ts @@ -132,6 +132,9 @@ function obfuscateHtmlClassNames({ const usedKeys: string[] = []; const parser = new htmlparser2.Parser({ + onprocessinginstruction(name, data) { + modifiedHtml += `<${data}>`; + }, onopentag(tagName, attribs) { if (tagName === "script") { isScriptTag = true;