soranoo / next-css-obfuscator

A package deeply inspired by PostCSS-Obfuscator but for Next.js.
https://next-css-obfuscator.vercel.app
MIT License
71 stars 3 forks source link

Incorrect Regex/String Filtering at `whiteListedFolderPaths`, `blackListedFolderPaths` and `classIgnore` Options #12

Closed hoangnhan2ka3 closed 7 months ago

hoangnhan2ka3 commented 7 months ago

And the contestant this time is has-[foo]:

Please refer to: Styling based on descendants (has-{modifier})

image

Some obfuscated ✅, some not ⛔:

image

Replaced ✅ (No style lost):

image

image

Have another nice day 💕

soranoo commented 7 months ago

I don't see any problem with the extraction regex

image

hoangnhan2ka3 commented 7 months ago

hmmm why

image

I tried delete both .next/cache and css-obfuscator folder but nothing change

hoangnhan2ka3 commented 7 months ago

Maybe the problem is that rounded-none or border-none haven't been obfuscated, it's a valid TW class?

soranoo commented 7 months ago

The regex doesn't specifically match the Tailwind class, it matches all words

hoangnhan2ka3 commented 7 months ago

Hmmm... so why max-h-full and p-0 have been obfuscated but not rounded-none, border-none or outline-none?

I guess it's not a problem with the word none :)))

hoangnhan2ka3 commented 7 months ago

Maybe it's truth @soranoo

image

soranoo commented 7 months ago

I found I forgot to ask for ur config.

May I have your config file?

hoangnhan2ka3 commented 7 months ago

For now:

module.exports = {
    enable: true, // Enable or disable the plugin.
    mode: "predictable", // Obfuscate mode, "random" or "simplify".
    buildFolderPath: ".next", // Build folder of your project.
    classConversionJsonFolderPath: "./css-obfuscator", // The folder path to store the before obfuscate and after obfuscated classes conversion table.
    refreshClassConversionJson: false, // Refresh the class conversion JSON file.

    classLength: 6, // Length of the obfuscated class name.
    classPrefix: "", // Prefix of the obfuscated class name.
    classSuffix: "", // Suffix of the obfuscated class name.

    classIgnore: [
        "no",
        "dark",
        "light",
        "no-transition",
        "opa-hidden",
        "big",
        "small",
        /lenis*/
    ], // The class names to be ignored during obfuscation.

    allowExtensions: [".jsx", ".tsx", ".js", ".ts", ".html", ".rsc"], // The file extensions to be processed.

    contentIgnoreRegexes: [/\.jsxs\)\("\w+"/g], // The regexes to match the file content to be ignored during obfuscation.

    whiteListedFolderPaths: [], // Only obfuscate files in these folders

    blackListedFolderPaths: ["./.next/cache"], // Don't obfuscate files in these folders

    enableMarkers: false, // Enable or disable the obfuscate marker classes.
    markers: ["obf"], // Classes that indicate component(s) need to obfuscate.
    removeMarkersAfterObfuscated: true, // Remove the obfuscation markers from HTML elements after obfuscation.

    removeOriginalCss: true, // Delete original CSS from CSS files if it has a obfuscated version.

    generatorSeed: 840817818898, // The seed for the random generator.

    logLevel: "info", // Log level
};
hoangnhan2ka3 commented 7 months ago

Hmmm I don't think....

image

hoangnhan2ka3 commented 7 months ago

Oh yes sir :))))))

image

After remove

image

It's OK now:

image

Why, it's not a regex

soranoo commented 7 months ago

Btw would you mind giving a meaningful issue title next time?

hoangnhan2ka3 commented 7 months ago

yes yes, my fault 🫡