diff --git a/src/utils.js b/src/utils.js
index ba615cd0..16086254 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -63,8 +63,11 @@ export function getExportCode(html, replacers, options) {
let exportCode = html;
if (!options.interpolate) {
- // eslint-disable-next-line no-param-reassign
- exportCode = JSON.stringify(exportCode);
+ exportCode = JSON.stringify(exportCode)
+ // Invalid in JavaScript but valid HTML
+ .replace(/[\u2028\u2029]/g, (str) =>
+ str === '\u2029' ? '\\u2029' : '\\u2028'
+ );
}
for (const replacer of replacers) {
diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap
index e15095b7..09d7258c 100644
--- a/test/__snapshots__/loader.test.js.snap
+++ b/test/__snapshots__/loader.test.js.snap
@@ -4,16 +4,10 @@ exports[`loader should not failed contain invisible spaces: errors 1`] = `Array
exports[`loader should not failed contain invisible spaces: module 1`] = `
"// Exports
-module.exports = \\"
\\\\n - \\\\\\\\u2028 -
\\\\n - \\\\\\\\u2029 -
\\\\n
\\\\n\\";"
+module.exports = \\"- \\\\\\\\u2028 - \\\\u2028 Text \\\\u2028
- \\\\\\\\u2029 - \\\\u2029 Text \\\\u2029
\\";"
`;
-exports[`loader should not failed contain invisible spaces: result 1`] = `
-"
- - \\\\u2028 -
- - \\\\u2029 -
-
-"
-`;
+exports[`loader should not failed contain invisible spaces: result 1`] = `"- \\\\u2028 -
Text
- \\\\u2029 -
Text
"`;
exports[`loader should not failed contain invisible spaces: warnings 1`] = `Array []`;
diff --git a/test/fixtures/invisible-space.html b/test/fixtures/invisible-space.html
index 2bb649fa..5e038058 100644
--- a/test/fixtures/invisible-space.html
+++ b/test/fixtures/invisible-space.html
@@ -1,4 +1 @@
-
+- \u2028 -
Text
- \u2029 -
Text
\ No newline at end of file
diff --git a/test/loader.test.js b/test/loader.test.js
index 0df41ef5..e6d5a26c 100644
--- a/test/loader.test.js
+++ b/test/loader.test.js
@@ -1,3 +1,6 @@
+import fs from 'fs';
+import path from 'path';
+
import {
compile,
getCompiler,
@@ -34,12 +37,19 @@ describe('loader', () => {
});
it('should not failed contain invisible spaces', async () => {
+ const source = fs.readFileSync(
+ path.resolve(__dirname, './fixtures/invisible-space.html')
+ );
+
+ expect(/[\u2028\u2029]/.test(source)).toBe(true);
+
const compiler = getCompiler('invisible-space.js');
const stats = await compile(compiler);
- expect(getModuleSource('./invisible-space.html', stats)).toMatchSnapshot(
- 'module'
- );
+ const moduleSource = getModuleSource('./invisible-space.html', stats);
+
+ expect(moduleSource).toMatchSnapshot('module');
+ expect(/[\u2028\u2029]/.test(moduleSource)).toBe(false);
expect(
execute(readAsset('main.bundle.js', compiler, stats))
).toMatchSnapshot('result');