Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minifier] closing tags should be escaped #9723

Closed
layershifter opened this issue Nov 8, 2024 · 2 comments
Closed

[minifier] closing tags should be escaped #9723

layershifter opened this issue Nov 8, 2024 · 2 comments
Labels

Comments

@layershifter
Copy link

Describe the bug

We use Webpack + html-webpack-plugin + terser-webpack-plugin with SWC as a minifier.

We inline some JS into a .ejs template, basically:

<body>
  <script><%= someVar =></script>
</body>

It works fine with Terser & esbuild as minifiers, but breaks on SWC.

I traced the problem and it looks that SWC does not escape tags and this breaks the template as someVar contains + </script>, so we get:

<body>
  <script>"" + "</script>";</script>
  <!--          ⬆️ a closing tag 💣 -->
</body>

Input code

export const foo = "</script>"

Config

N/A

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.9.1&code=H4sIAAAAAAAAA0utKMgvKlFIzs8rLlFIy89XsFVQstEvTi7KLCixUwIAa3ctVB4AAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAxE9zkF8rqLKIsueoceAlEnIuIn7EhFUe5eIJC2O%2FuNRzPeByFgJQUPsecxL0FGwnjtmVByLN%2BZAKeApKIODLeuMhWJ44aVHKcALOOCXExI0ziNzQDGe8KMZ2kIG7Pa6Tn9RipvQ0Si%2F8NyKt1iLv%2BZOLRUsP61VbG9UuqeDe7wPephpXIlmp7dWN84Pk9GmjkVAQAA

SWC Info output

@swc/core@1.9.1

Expected behavior

SWC should escape closing tags like Terser and esbuild:

export const foo = "<\/script>"

Terser

image

esbuild

REPL

image

Actual behavior

SWC produces:

export const foo = "</script>"

REPL

Version

@swc/core@1.9.1

Additional context

No response

@kdy1
Copy link
Member

kdy1 commented Nov 8, 2024

Duplicate of #7602

@kdy1 kdy1 marked this as a duplicate of #7602 Nov 8, 2024
@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2024
@kdy1
Copy link
Member

kdy1 commented Nov 11, 2024

#9729 will implement this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants