Skip to content

[Bug]: HtmlRspackPlugin escapes certain characters even when using <%= #10826

Open
@markmssd

Description

@markmssd

System Info

System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Max
Memory: 715.94 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.16.0 - ~/.nvm/versions/node/v22.16.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.16.0/bin/npm
pnpm: 9.15.4 - ~/Library/pnpm/pnpm
bun: 1.1.8 - ~/.bun/bin/bun
Browsers:
Brave Browser: 126.1.67.123
Chrome: 138.0.7204.50
Edge: 137.0.3296.93
Safari: 18.5
npmPackages:
@rspack/cli: ^1.4.1 => 1.4.1
@rspack/core: ^1.4.1 => 1.4.1

Details

When replacing HtmlWebpackPlugin with rspack.HtmlRspackPlugin.

There's a few things I wanted to point out about the Rspack version:

  • In EJS, <%- is used for unescaped outputs and <%= for escaped, but in Rspack, it's the opposite: <%= for unescaped and <%- for escaped. Is that intended? EDIT: This is the same behaviour as HtmlWebpackPlugin

  • When using <%= for outputting unescaped strings, <% still gets escaped as &lt;%=. In the index.ejs template, we have <title><%= title %></title>, and in the rspack.HtmlRspackPlugin, we configured the templateParameter as title: '<%= title %>' (basically we don't want to change it, but it fails if we don't specify it, so we replace it with the same EJS string). Note that other characters like & also get escaped.

Reproduce link

https://github.com/markmssd/rspack-repro/tree/html-rspack-plugin-escaped-ejs

Reproduce Steps

git clone https://github.com/markmssd/rspack-repro/tree/html-rspack-plugin-escaped-ejs
pnpm install
pnpm build:rspack

Look at the src/index.ejs file. It has 2 title tags: one that should be escaped, and one that should not.

Now look at rspack.config.mjs. I have configured both HtmlWebpackPlugin and HtmlRspackPlugin, and each outputs in its own file.

Now, open both rspack-dist/html.index.ejs and rspack-dist/rspack.index.ejs. Notice that they are not the same. Rspack's one has both titles escaped.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions