@@ -13,6 +13,7 @@ import ignoreScriptsConfig from './cases/ignore-scripts/webpack.config';
13
13
import ignoreHtmlsConfig from './cases/ignore-htmls/webpack.config' ;
14
14
import ignoreScriptsAndHtmlsConfig from './cases/ignore-scripts-and-htmls/webpack.config' ;
15
15
import filenameWithSpecialCharactersConfig from './cases/filename-with-special-characters/webpack.config' ;
16
+ import escapeScriptTagEndConfig from './cases/escape-script-end-tag/webpack.config' ;
16
17
17
18
describe ( 'HtmlInlineScriptPlugin' , ( ) => {
18
19
it ( 'should build simple webpack config without error' , async ( ) => {
@@ -358,6 +359,38 @@ describe('HtmlInlineScriptPlugin', () => {
358
359
await webpackPromise ;
359
360
} ) ;
360
361
362
+ it ( 'should escape any "</script>" appears in source' , async ( ) => {
363
+ const webpackPromise = new Promise ( ( resolve ) => {
364
+ const compiler = webpack ( escapeScriptTagEndConfig ) ;
365
+
366
+ compiler . run ( ( error , stats ) => {
367
+ expect ( error ) . toBeNull ( ) ;
368
+
369
+ const statsErrors = stats ?. compilation . errors ;
370
+ expect ( statsErrors ?. length ) . toBe ( 0 ) ;
371
+
372
+ const result = fs . readFileSync (
373
+ path . join ( __dirname , 'cases/escape-script-end-tag/dist/index.html' ) ,
374
+ 'utf8' ,
375
+ ) ;
376
+
377
+ const expected = fs . readFileSync (
378
+ path . join ( __dirname , 'cases/escape-script-end-tag/expected/index.html' ) ,
379
+ 'utf8' ,
380
+ ) ;
381
+ expect ( result ) . toBe ( expected ) ;
382
+
383
+ const expectedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/escape-script-end-tag/expected/' ) ) ;
384
+ const generatedFileList = fs . readdirSync ( path . join ( __dirname , 'cases/escape-script-end-tag/dist/' ) ) ;
385
+ expect ( expectedFileList . sort ( ) ) . toEqual ( generatedFileList . sort ( ) ) ;
386
+
387
+ resolve ( true ) ;
388
+ } ) ;
389
+ } ) ;
390
+
391
+ await webpackPromise ;
392
+ } ) ;
393
+
361
394
it ( 'should build throw error if options passed to plugin is old options format' , async ( ) => {
362
395
const initializedPlugin = ( ) => {
363
396
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-new
0 commit comments