@@ -13,6 +13,7 @@ import ignoreScriptsConfig from './cases/ignore-scripts/webpack.config';
1313import ignoreHtmlsConfig from './cases/ignore-htmls/webpack.config' ;
1414import ignoreScriptsAndHtmlsConfig from './cases/ignore-scripts-and-htmls/webpack.config' ;
1515import filenameWithSpecialCharactersConfig from './cases/filename-with-special-characters/webpack.config' ;
16+ import escapeScriptTagEndConfig from './cases/escape-script-end-tag/webpack.config' ;
1617
1718describe ( 'HtmlInlineScriptPlugin' , ( ) => {
1819 it ( 'should build simple webpack config without error' , async ( ) => {
@@ -358,6 +359,38 @@ describe('HtmlInlineScriptPlugin', () => {
358359 await webpackPromise ;
359360 } ) ;
360361
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+
361394 it ( 'should build throw error if options passed to plugin is old options format' , async ( ) => {
362395 const initializedPlugin = ( ) => {
363396 // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-new
0 commit comments