BjornTheProgrammer / bun-plugin-html

A plugin for bun build which allows html entrypoints
MIT License
34 stars 2 forks source link

Can't inline script such as `const x = '</script>'` #4

Closed seiyab closed 11 months ago

seiyab commented 11 months ago

Hi. Trying to this interesting and useful plugin, I found inlining scripts that contains </script> enexpectedly closes script tag.

Adding a context, I'm trying to bundle React application into a single HTML. React (probably react-dom) contains div.innerHTML = "<script></script>";, at least as of 18.2.0.

seiyab commented 11 months ago

html-inline-script-webpack-plugin probably handles it like this:

(asset.source() as string).replace(/(<)(\/script>)/g, '\\x3C$2')

https://github.com/icelam/html-inline-script-webpack-plugin/blob/fd19ece98f3f1b13a02a61dd481f50b31cb8945d/src/HtmlInlineScriptPlugin.ts#L98

BjornTheProgrammer commented 11 months ago

Would you be willing to make a minimum reproducible example of this bug?

seiyab commented 11 months ago

OK, I will. Which do you prefer?

BjornTheProgrammer commented 11 months ago

The more practical one with a minimal React example. Also, note that the code has been significantly reworked in v1.3.1, so try upgrading first.

seiyab commented 11 months ago

Here is. https://github.com/seiyab/repro/tree/main/bun-plugin-html-inline

BjornTheProgrammer commented 11 months ago

@seiyab this should now be fixed as of v1.3.2. Thank you for your bug report! Let me know if you have any other issues.

seiyab commented 11 months ago

I confirmed v1.3.2 works fine 👍 🎉 🥇