From 25bb2454d485821f314008258c876d9158804fba Mon Sep 17 00:00:00 2001 From: Freeman Date: Tue, 12 Mar 2024 14:03:24 +0000 Subject: [PATCH 1/5] Delete jest.config.js --- jest.config.js | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 26eba3a..0000000 --- a/jest.config.js +++ /dev/null @@ -1,6 +0,0 @@ -/** @type {import('ts-jest').JestConfigWithTsJest} */ -module.exports = { - preset: "ts-jest", - testEnvironment: "node", - testPathIgnorePatterns: ["/node_modules/", "/dist/", "/coverage/"], -}; From 00331cd80990e90daac5f94028d5fed662d773e3 Mon Sep 17 00:00:00 2001 From: Freeman Date: Tue, 12 Mar 2024 14:03:58 +0000 Subject: [PATCH 2/5] Fixed #30 --- package.json | 2 +- src/utils.ts | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 4f4b5a1..b7c41f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-css-obfuscator", - "version": "2.2.13", + "version": "2.2.14-beta.2", "description": "A package deeply inspired by PostCSS-Obfuscator but for Next.js.", "main": "dist/index.js", "type": "commonjs", diff --git a/src/utils.ts b/src/utils.ts index 036bc08..b106129 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -58,7 +58,7 @@ function setLogLevel(level: LogLevel) { //! ==================== const HTML_CHARACTER_ENTITY_CONVERSION: HtmlCharacterEntityConversion = { "\\&": "&", - "&": "&", //? must later than "\\&" + "&": "&", //? must later than "\\&", ref issue: #30 "\\<": "<", "\\>": ">", '\\"': """, @@ -203,11 +203,11 @@ function replaceJsonKeysInFiles( //! rollback if (htmlOriginal !== html) { - const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass); - addKeysToRegistery(usedKeys); - if (htmlOriginal !== obfuscatedContent) { - fileContent = fileContent.replace(htmlOriginal, html); - } + // const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass); + // addKeysToRegistery(usedKeys); + // if (htmlOriginal !== obfuscatedContent) { + fileContent = fileContent.replace(htmlOriginal, html); + // } } @@ -258,7 +258,7 @@ function replaceJsonKeysInFiles( ); // const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion); - + fileContent = obfuscatedContent; addKeysToRegistery(usedKeys); } @@ -299,9 +299,10 @@ function obfuscateKeys( let keyUse = key.slice(1); if (useHtmlEntity) { - for (const [key, value] of Object.entries(HTML_CHARACTER_ENTITY_CONVERSION)) { - keyUse = keyUse.replace(new RegExp(value, "g"), key); - } + const regex = new RegExp(`(${Object.keys(HTML_CHARACTER_ENTITY_CONVERSION).join("|")})`, "g"); + keyUse = keyUse.replace(regex, (m: string) => { + return HTML_CHARACTER_ENTITY_CONVERSION[m] + }); } keyUse = escapeRegExp(keyUse.replace(/\\/g, "")); From 940ea2489969d536245ef1b90a89f0f650935d7e Mon Sep 17 00:00:00 2001 From: Freeman Date: Wed, 13 Mar 2024 10:54:55 +0000 Subject: [PATCH 3/5] Reintroduced HTML AST Based Replace Strategy #25 --- .npmignore | 1 + package-lock.json | 352 ++++++++++++++++++++++++++++++++++++-- package.json | 3 +- src/handlers/html.test.ts | 65 +++++-- src/handlers/html.ts | 63 ++++++- src/utils.test.ts | 1 - src/utils.ts | 99 ++++++----- 7 files changed, 498 insertions(+), 86 deletions(-) diff --git a/.npmignore b/.npmignore index 851f42f..f757e7b 100644 --- a/.npmignore +++ b/.npmignore @@ -8,3 +8,4 @@ demos .prettierignore .prettierrc *.test.* +coverage diff --git a/package-lock.json b/package-lock.json index 7efe86c..594bad7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "next-css-obfuscator", - "version": "2.2.11-beta.0", + "version": "2.2.14-beta.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "next-css-obfuscator", - "version": "2.2.11-beta.0", + "version": "2.2.14-beta.2", "license": "MIT", "dependencies": { "@babel/generator": "^7.23.6", @@ -26,12 +26,26 @@ "@types/node": "^20.8.10", "@types/react": "^18.2.31", "@types/yargs": "^17.0.32", + "@vitest/coverage-v8": "^1.3.1", "prettier": "^3.2.4", "tslib": "^2.6.2", "typescript": "^5.0.2", "vitest": "^1.3.1" } }, + "node_modules/@ampproject/remapping": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", + "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", + "dev": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/@babel/code-frame": { "version": "7.23.5", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", @@ -314,6 +328,12 @@ "node": ">=6.9.0" } }, + "node_modules/@bcoe/v8-coverage": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", + "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", + "dev": true + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.19.12", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.19.12.tgz", @@ -682,6 +702,15 @@ "node": ">=12" } }, + "node_modules/@istanbuljs/schema": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/@jest/schemas": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", @@ -695,13 +724,13 @@ } }, "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", - "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", + "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", "dependencies": { - "@jridgewell/set-array": "^1.0.1", + "@jridgewell/set-array": "^1.2.1", "@jridgewell/sourcemap-codec": "^1.4.10", - "@jridgewell/trace-mapping": "^0.3.9" + "@jridgewell/trace-mapping": "^0.3.24" }, "engines": { "node": ">=6.0.0" @@ -716,9 +745,9 @@ } }, "node_modules/@jridgewell/set-array": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", - "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", + "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", "engines": { "node": ">=6.0.0" } @@ -729,9 +758,9 @@ "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.21", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.21.tgz", - "integrity": "sha512-SRfKmRe1KvYnxjEMtxEr+J4HIeMX5YBg/qhRHpxEIGjhX1rshcHlnFUE9K0GazhVKWM7B+nARSkV8LuvJdJ5/g==", + "version": "0.3.25", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", + "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" @@ -936,6 +965,12 @@ "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", "dev": true }, + "node_modules/@types/istanbul-lib-coverage": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", + "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==", + "dev": true + }, "node_modules/@types/node": { "version": "20.8.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.10.tgz", @@ -983,6 +1018,33 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "node_modules/@vitest/coverage-v8": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-1.3.1.tgz", + "integrity": "sha512-UuBnkSJUNE9rdHjDCPyJ4fYuMkoMtnghes1XohYa4At0MS3OQSAo97FrbwSLRshYsXThMZy1+ybD/byK5llyIg==", + "dev": true, + "dependencies": { + "@ampproject/remapping": "^2.2.1", + "@bcoe/v8-coverage": "^0.2.3", + "debug": "^4.3.4", + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1", + "istanbul-lib-source-maps": "^4.0.1", + "istanbul-reports": "^3.1.6", + "magic-string": "^0.30.5", + "magicast": "^0.3.3", + "picocolors": "^1.0.0", + "std-env": "^3.5.0", + "test-exclude": "^6.0.0", + "v8-to-istanbul": "^9.2.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "vitest": "1.3.1" + } + }, "node_modules/@vitest/expect": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-1.3.1.tgz", @@ -1142,6 +1204,22 @@ "node": ">= 4.5.0" } }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -1210,6 +1288,18 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true + }, + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -1416,6 +1506,12 @@ "@types/estree": "^1.0.0" } }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1447,6 +1543,26 @@ "node": "*" } }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", @@ -1455,6 +1571,21 @@ "node": ">=4" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true + }, "node_modules/htmlparser2": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz", @@ -1473,6 +1604,16 @@ "entities": "^4.5.0" } }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -1492,6 +1633,56 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-report": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", + "dev": true, + "dependencies": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^4.0.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-lib-source-maps": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-4.0.1.tgz", + "integrity": "sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "istanbul-lib-coverage": "^3.0.0", + "source-map": "^0.6.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-reports": { + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.7.tgz", + "integrity": "sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==", + "dev": true, + "dependencies": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1539,6 +1730,18 @@ "get-func-name": "^2.0.1" } }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/magic-string": { "version": "0.30.8", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.8.tgz", @@ -1551,12 +1754,50 @@ "node": ">=12" } }, + "node_modules/magicast": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.3.3.tgz", + "integrity": "sha512-ZbrP1Qxnpoes8sz47AM0z08U+jW6TyRgZzcWy3Ma3vDhJttwMwAFDMMQFobwdBxByBD46JYmxRzeF7w2+wJEuw==", + "dev": true, + "dependencies": { + "@babel/parser": "^7.23.6", + "@babel/types": "^7.23.6", + "source-map-js": "^1.0.2" + } + }, + "node_modules/make-dir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", + "dev": true, + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/mlly": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.6.1.tgz", @@ -1592,6 +1833,24 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -1759,6 +2018,21 @@ "fsevents": "~2.3.2" } }, + "node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -1876,6 +2150,32 @@ "integrity": "sha512-UfJMcSJc+SEXEl9lH/VLHSZbThQyLpw1vLO1Lb+j4RWDvG3N2f7yj3PVQA3cmkTBNldJ9eFnM+xEXxHIXrYiJw==", "dev": true }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/test-exclude": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", + "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==", + "dev": true, + "dependencies": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^7.1.4", + "minimatch": "^3.0.4" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/tinybench": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.6.0.tgz", @@ -1954,6 +2254,20 @@ "integrity": "sha512-Am1ousAhSLBeB9cG/7k7r2R0zj50uDRlZHPGbazid5s9rlF1F/QKYObEKSIunSjIOkJZqwRRLpvewjEkM7pSqg==", "deprecated": "Please see https://github.com/lydell/urix#deprecated" }, + "node_modules/v8-to-istanbul": { + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.2.0.tgz", + "integrity": "sha512-/EH/sDgxU2eGxajKdwLCDmQ4FWq+kpi3uCmBGpw1xJtnAxEjlD8j8PEiGWpCIMIs3ciNAgH0d3TTJiUkYzyZjA==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.12", + "@types/istanbul-lib-coverage": "^2.0.1", + "convert-source-map": "^2.0.0" + }, + "engines": { + "node": ">=10.12.0" + } + }, "node_modules/vite": { "version": "5.1.5", "resolved": "https://registry.npmjs.org/vite/-/vite-5.1.5.tgz", @@ -2277,6 +2591,12 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", @@ -2285,6 +2605,12 @@ "node": ">=10" } }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", diff --git a/package.json b/package.json index b7c41f7..81bcb1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-css-obfuscator", - "version": "2.2.14-beta.2", + "version": "2.2.14-beta.4", "description": "A package deeply inspired by PostCSS-Obfuscator but for Next.js.", "main": "dist/index.js", "type": "commonjs", @@ -28,6 +28,7 @@ "@types/node": "^20.8.10", "@types/react": "^18.2.31", "@types/yargs": "^17.0.32", + "@vitest/coverage-v8": "^1.3.1", "prettier": "^3.2.4", "tslib": "^2.6.2", "typescript": "^5.0.2", diff --git a/src/handlers/html.test.ts b/src/handlers/html.test.ts index 8a56418..b4506de 100644 --- a/src/handlers/html.test.ts +++ b/src/handlers/html.test.ts @@ -47,7 +47,7 @@ describe("obfuscateHtmlClassNames", () => { const selectorConversion: SelectorConversion = { ".foo": ".a" }; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion); + const result = obfuscateHtmlClassNames({ html, selectorConversion }); // Assert expect(result.obfuscatedContent).toEqual(`
`); @@ -61,7 +61,7 @@ describe("obfuscateHtmlClassNames", () => { const keyClass = "key"; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion, keyClass); + const result = obfuscateHtmlClassNames({ html, selectorConversion, obfuscateMarkerClass: keyClass }); // Assert expect(result.obfuscatedContent).toEqual(`
`); @@ -75,23 +75,50 @@ describe("obfuscateHtmlClassNames", () => { const keyClass = "key"; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion, keyClass); + const result = obfuscateHtmlClassNames({ html, selectorConversion, obfuscateMarkerClass: keyClass }); // Assert expect(result.obfuscatedContent).toEqual(`
`); expect(result.usedKeys).to.deep.equal([]); }); - it("should handle self-closing tags", () => { + it("should handle script tags", () => { + // Arrange + const html = ``; + const selectorConversion: SelectorConversion = { ".fol": ".a", ".foo": ".b" }; + + // Act + const result = obfuscateHtmlClassNames({ html, selectorConversion, obfuscateMarkerClass: "" }); + + // Assert + expect(result.obfuscatedContent).toEqual(``); + expect(result.usedKeys).to.deep.equal([".fol", ".foo"]); + }); + + it("should handle void tags", () => { // Arrange const html = ``; const selectorConversion: SelectorConversion = { ".foo": ".a" }; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion); + const result = obfuscateHtmlClassNames({ html, selectorConversion }); + + // Assert + expect(result.obfuscatedContent).toEqual(``); + expect(result.usedKeys).to.deep.equal([".foo"]); + }); + + + it("should handle comments", () => { + // Arrange + const html = `
`; + const selectorConversion: SelectorConversion = { ".foo": ".a" }; + + // Act + const result = obfuscateHtmlClassNames({ html, selectorConversion }); // Assert - expect(result.obfuscatedContent).toEqual(``); + expect(result.obfuscatedContent).toEqual(`
`); expect(result.usedKeys).to.deep.equal([".foo"]); }); @@ -101,7 +128,7 @@ describe("obfuscateHtmlClassNames", () => { const selectorConversion: SelectorConversion = {}; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion); + const result = obfuscateHtmlClassNames({ html, selectorConversion }); // Assert expect(result.obfuscatedContent).toEqual("
"); @@ -114,7 +141,7 @@ describe("obfuscateHtmlClassNames", () => { const selectorConversion: SelectorConversion = { ".foo": ".a" }; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion); + const result = obfuscateHtmlClassNames({ html, selectorConversion }); // Assert expect(result.obfuscatedContent).toEqual(""); @@ -127,7 +154,7 @@ describe("obfuscateHtmlClassNames", () => { const selectorConversion: SelectorConversion = { ".foo": ".a", ".bar": ".b", ".baz": ".c" }; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion); + const result = obfuscateHtmlClassNames({ html, selectorConversion }); // Assert expect(result.obfuscatedContent).toEqual(`
`); @@ -135,16 +162,16 @@ describe("obfuscateHtmlClassNames", () => { }); it("should handle HTML with nested structures and multiple classes", () => { - // Arrange - const html = `
`; - const selectorConversion: SelectorConversion = { ".foo": ".a", ".bar": ".b", ".baz": ".c" }; + // Arrange + const html = `
`; + const selectorConversion: SelectorConversion = { ".foo": ".a", ".bar": ".b", ".baz": ".c" }; - // Act - const result = obfuscateHtmlClassNames(html, selectorConversion); + // Act + const result = obfuscateHtmlClassNames({ html, selectorConversion }); - // Assert - expect(result.obfuscatedContent).toEqual(`
`); - expect(result.usedKeys).to.deep.equal([".foo", ".bar", ".baz"]); + // Assert + expect(result.obfuscatedContent).toEqual(`
`); + expect(result.usedKeys).to.deep.equal([".foo", ".bar", ".baz"]); }); it("should handle HTML with obfuscate marker class", () => { @@ -154,7 +181,7 @@ describe("obfuscateHtmlClassNames", () => { const obfuscateMarkerClass = "key"; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion, obfuscateMarkerClass); + const result = obfuscateHtmlClassNames({ html, selectorConversion, obfuscateMarkerClass }); // Assert expect(result.obfuscatedContent).toEqual(`
`); @@ -168,7 +195,7 @@ describe("obfuscateHtmlClassNames", () => { const obfuscateMarkerClass = "key"; // Act - const result = obfuscateHtmlClassNames(html, selectorConversion, obfuscateMarkerClass); + const result = obfuscateHtmlClassNames({ html, selectorConversion, obfuscateMarkerClass }); // Assert expect(result.obfuscatedContent).toEqual(`
`); diff --git a/src/handlers/html.ts b/src/handlers/html.ts index 82f3fa8..1ec4c94 100644 --- a/src/handlers/html.ts +++ b/src/handlers/html.ts @@ -2,6 +2,7 @@ import * as htmlparser2 from "htmlparser2"; import { log, obfuscateKeys } from "../utils"; import { SelectorConversion } from "../types"; +import { obfuscateJs } from "./js"; //! deprecated function findHtmlTagContentsRecursive(content: string, targetTag: string, targetClass: string | null = null, foundTagContents: string[] = [], deep: number = 0, maxDeep: number = -1) { @@ -107,20 +108,36 @@ function findHtmlTagContentsByClass(content: string, targetClass: string) { } } -function obfuscateHtmlClassNames( +function obfuscateHtmlClassNames({ + html, + selectorConversion, + obfuscateMarkerClass = "", + contentIgnoreRegexes = [], +}: { html: string, selectorConversion: SelectorConversion, - obfuscateMarkerClass?: string -) { + obfuscateMarkerClass?: string, + contentIgnoreRegexes?: RegExp[], +}) { + const voidTags = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]; + let modifiedHtml = ""; let insideObsClassScope = false; let ObsClassScopeTagCount = 0; // Count of the obfuscate class scope tag (for nested tags with the same class name) let ObsClassScopeTag = ""; + let scriptContent = ""; + let isScriptTag = false; + const usedKeys: string[] = []; const parser = new htmlparser2.Parser({ onopentag(tagName, attribs) { + if (tagName === "script") { + isScriptTag = true; + scriptContent = ""; // reset script content for a new script tag + } + if (attribs.class) { // Check if the current tag is within the scope of the obfuscate class if (!insideObsClassScope && obfuscateMarkerClass && attribs.class.includes(obfuscateMarkerClass)) { @@ -128,13 +145,13 @@ function obfuscateHtmlClassNames( ObsClassScopeTag = tagName; } - // attribs.class = classNames.join(" "); if (insideObsClassScope || !obfuscateMarkerClass) { const { obfuscatedContent, usedKeys: _usedKeys } = obfuscateKeys(selectorConversion, attribs.class, [], true); usedKeys.push(..._usedKeys); // Update the class to the modified class names attribs.class = obfuscatedContent; } + } if (insideObsClassScope && tagName === ObsClassScopeTag) { @@ -146,12 +163,46 @@ function obfuscateHtmlClassNames( for (const key in attribs) { modifiedHtml += ` ${key}="${attribs[key]}"`; } - modifiedHtml += ">"; + if (voidTags.includes(tagName)) { + modifiedHtml += " />"; + } else { + modifiedHtml += ">"; + } + }, + oncomment(comment) { + modifiedHtml += ``; }, ontext(text) { - modifiedHtml += text; + if (isScriptTag) { + scriptContent += text; + } else { + modifiedHtml += text; + } }, onclosetag(tagname) { + if (voidTags.includes(tagname)) { + return; + } + + if (tagname === "script" && isScriptTag) { + isScriptTag = false; + let obfuscatedScriptContent = scriptContent; + Object.keys(selectorConversion).forEach((key) => { + const className = key.slice(1); + const obfuscatedJs = obfuscateJs( + obfuscatedScriptContent, + className, + { [key]: selectorConversion[key] }, + "{a HTML file path}", + contentIgnoreRegexes, + ); + if (obfuscatedJs !== obfuscatedScriptContent) { + obfuscatedScriptContent = obfuscatedJs; + usedKeys.push(key); + } + }); + modifiedHtml += `${obfuscatedScriptContent}`; + } modifiedHtml += ``; if (insideObsClassScope && tagname === ObsClassScopeTag) { diff --git a/src/utils.test.ts b/src/utils.test.ts index 736d1b4..54505ee 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -275,7 +275,6 @@ describe("seedableSimplifyString", () => { // Act const result = seedableSimplifyString(input, "seed"); - console.log(result); // Assert expect(result.randomString).toHaveLength(1); // Should contain one random character diff --git a/src/utils.ts b/src/utils.ts index b106129..aa61603 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -58,7 +58,6 @@ function setLogLevel(level: LogLevel) { //! ==================== const HTML_CHARACTER_ENTITY_CONVERSION: HtmlCharacterEntityConversion = { "\\&": "&", - "&": "&", //? must later than "\\&", ref issue: #30 "\\<": "<", "\\>": ">", '\\"': """, @@ -170,52 +169,53 @@ function replaceJsonKeysInFiles( const htmlRegex = new RegExp(`(<(.*)>(.*)<\/([^br][A-Za-z0-9]+)>)`, 'g'); const htmlMatch = fileContent.match(htmlRegex); if (htmlMatch) { - let html = htmlMatch[0]; - const htmlOriginal = html; + const htmlOriginal = htmlMatch[0]; + // let html = htmlOriginal; //! rollback - const tagContents = findHtmlTagContentsByClass(html, obfuscateMarkerClass); - tagContents.forEach(tagContent => { - const { obfuscatedContent, usedKeys } = obfuscateKeys(classConversion, tagContent, contentIgnoreRegexes); - addKeysToRegistery(usedKeys); - if (tagContent !== obfuscatedContent) { - html = html.replace(tagContent, obfuscatedContent); - log("debug", `Obscured keys under HTML tag in file:`, normalizePath(filePath)); - } - }); + // const tagContents = findHtmlTagContentsByClass(html, obfuscateMarkerClass); + // tagContents.forEach(tagContent => { + // const { obfuscatedContent, usedKeys } = obfuscateKeys(classConversion, tagContent, contentIgnoreRegexes); + // addKeysToRegistery(usedKeys); + // if (tagContent !== obfuscatedContent) { + // html = html.replace(tagContent, obfuscatedContent); + // log("debug", `Obscured keys under HTML tag in file:`, normalizePath(filePath)); + // } + // }); //! rollback - const scriptTagContents = findHtmlTagContents(html, "script"); - scriptTagContents.forEach(scriptTagContent => { - const obfuscateScriptContent = obfuscateJs( - scriptTagContent, - obfuscateMarkerClass, - classConversion, - filePath, - contentIgnoreRegexes, - enableJsAst - ); - if (scriptTagContent !== obfuscateScriptContent) { - html = html.replace(scriptTagContent, obfuscateScriptContent); - log("debug", `Obscured keys under HTML script tag in file:`, normalizePath(filePath)); - } - }); + // const scriptTagContents = findHtmlTagContents(html, "script"); + // scriptTagContents.forEach(scriptTagContent => { + // const obfuscateScriptContent = obfuscateJs( + // scriptTagContent, + // obfuscateMarkerClass, + // classConversion, + // filePath, + // contentIgnoreRegexes, + // enableJsAst + // ); + // if (scriptTagContent !== obfuscateScriptContent) { + // html = html.replace(scriptTagContent, obfuscateScriptContent); + // log("debug", `Obscured keys under HTML script tag in file:`, normalizePath(filePath)); + // } + // }); //! rollback - if (htmlOriginal !== html) { - // const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass); - // addKeysToRegistery(usedKeys); - // if (htmlOriginal !== obfuscatedContent) { - fileContent = fileContent.replace(htmlOriginal, html); - // } - } - - - // const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion, obfuscateMarkerClass); - // addKeysToRegistery(usedKeys); - // if (htmlOriginal !== obfuscatedContent) { + // if (htmlOriginal !== html) { // fileContent = fileContent.replace(htmlOriginal, html); // } + + //! NEW + const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames({ + html: htmlOriginal, + selectorConversion: classConversion, + obfuscateMarkerClass: obfuscateMarkerClass, + contentIgnoreRegexes: contentIgnoreRegexes, + }); + addKeysToRegistery(usedKeys); + if (htmlOriginal !== obfuscatedContent) { + fileContent = fileContent.replace(htmlOriginal, obfuscatedContent); + } } } else { const obfuscateScriptContent = obfuscateJs(fileContent, @@ -248,16 +248,23 @@ function replaceJsonKeysInFiles( fileContent = obfuscateScriptContent; log("debug", `Obscured keys in JSX related file:`, normalizePath(filePath)); } + } else if ([".html"].includes(fileExt)) { + //! NEW + const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames({ + html: fileContent, + selectorConversion: classConversion, + contentIgnoreRegexes: contentIgnoreRegexes, + }); + + fileContent = obfuscatedContent; + addKeysToRegistery(usedKeys); } else { - //! rollback const { obfuscatedContent, usedKeys } = obfuscateKeys( classConversion, fileContent, - contentIgnoreRegexes, - [".html"].includes(fileExt) + contentIgnoreRegexes ); - // const { obfuscatedContent, usedKeys } = obfuscateHtmlClassNames(fileContent, classConversion); fileContent = obfuscatedContent; addKeysToRegistery(usedKeys); @@ -307,7 +314,7 @@ function obfuscateKeys( keyUse = escapeRegExp(keyUse.replace(/\\/g, "")); //? sample: "text-sm w-full\n text-right\n p-2 flex gap-2 hover:bg-gray-100 dark:hover:bg-red-700 text-right" - let exactMatchRegex = new RegExp(`([\\s"'\\\`]|^)(${keyUse})(?=$|[\\s"'\\\`]|\\\\n)`, 'g'); // match exact wording & avoid ` ' "" + let exactMatchRegex = new RegExp(`([\\s"'\\\`]|^)(${keyUse})(?=$|[\\s"'\\\`]|\\\\n|\\\\",|\\\\"})`, 'g'); // match exact wording & avoid ` ' "" // exactMatchRegex = new RegExp(`([\\s"'\\\`]|^)(${keyUse})(?=$|[\\s"'\\\`])`, 'g'); // match exact wording & avoid ` ' "" const replacement = `$1` + selectorConversion[key].slice(1).replace(/\\/g, ""); @@ -439,8 +446,8 @@ function findContentBetweenMarker(content: string, targetStr: string, openMarker let targetStrPosition = content.indexOf(targetStr); const truncatedContents: string[] = []; while (targetStrPosition !== -1 && targetStrPosition < content.length) { - const openPos = findClosestSymbolPosition(content, "{", "}", targetStrPosition, "backward"); - const closePos = findClosestSymbolPosition(content, "{", "}", targetStrPosition, "forward"); + const openPos = findClosestSymbolPosition(content, openMarker, closeMarker, targetStrPosition, "backward"); + const closePos = findClosestSymbolPosition(content, openMarker, closeMarker, targetStrPosition, "forward"); if (openPos === -1 && closePos === -1) { break; From e901e5e6f539b2a94889efd9e3492f3978393126 Mon Sep 17 00:00:00 2001 From: Freeman Date: Wed, 13 Mar 2024 10:59:11 +0000 Subject: [PATCH 4/5] Deprecated HTML Entities Replacement #30 --- src/utils.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index aa61603..8c48fdc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -56,15 +56,17 @@ function setLogLevel(level: LogLevel) { //! ==================== //! Constants //! ==================== -const HTML_CHARACTER_ENTITY_CONVERSION: HtmlCharacterEntityConversion = { - "\\&": "&", - "\\<": "<", - "\\>": ">", - '\\"': """, - "\\'": "'", - - "\\2c": ",", //! not working -}; + +//! deprecated +// const HTML_CHARACTER_ENTITY_CONVERSION: HtmlCharacterEntityConversion = { +// "\\&": "&", +// "\\<": "<", +// "\\>": ">", +// '\\"': """, +// "\\'": "'", + +// "\\2c": ",", //! not working +// }; //! ==================== //! @@ -305,12 +307,13 @@ function obfuscateKeys( // let keyUse = escapeRegExp(key.slice(1).replace(/\\/g, "")); let keyUse = key.slice(1); - if (useHtmlEntity) { - const regex = new RegExp(`(${Object.keys(HTML_CHARACTER_ENTITY_CONVERSION).join("|")})`, "g"); - keyUse = keyUse.replace(regex, (m: string) => { - return HTML_CHARACTER_ENTITY_CONVERSION[m] - }); - } + //! deprecated + // if (useHtmlEntity) { + // const regex = new RegExp(`(${Object.keys(HTML_CHARACTER_ENTITY_CONVERSION).join("|")})`, "g"); + // keyUse = keyUse.replace(regex, (m: string) => { + // return HTML_CHARACTER_ENTITY_CONVERSION[m] + // }); + // } keyUse = escapeRegExp(keyUse.replace(/\\/g, "")); //? sample: "text-sm w-full\n text-right\n p-2 flex gap-2 hover:bg-gray-100 dark:hover:bg-red-700 text-right" From b6d71aeb6f4c75dbcc64cec78215a1b1cd7e0ee8 Mon Sep 17 00:00:00 2001 From: Freeman Date: Thu, 14 Mar 2024 16:23:24 +0000 Subject: [PATCH 5/5] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81bcb1e..81b61e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-css-obfuscator", - "version": "2.2.14-beta.4", + "version": "2.2.14", "description": "A package deeply inspired by PostCSS-Obfuscator but for Next.js.", "main": "dist/index.js", "type": "commonjs",