@@ -363,7 +363,7 @@ export default {
363363 }
364364
365365 // 移除样式文件
366- let style = document . getElementById ( this . getThemeStyleId ( this . getName ( ) ) )
366+ let style = document . getElementById ( this . getThemeStyleId ( this . parseNameHtmlSafely ( this . getName ( ) ) ) )
367367 if ( style ) {
368368 document . body . removeChild ( style )
369369 }
@@ -386,7 +386,7 @@ export default {
386386 let oldName = oldVal ? oldVal : this . _name
387387
388388 rename ( newName , oldName , this . terminalListener )
389- this . changeThemeFlag ( newName , oldName )
389+ this . changeThemeFlag ( this . parseNameHtmlSafely ( newName ) , this . parseNameHtmlSafely ( oldName ) )
390390 }
391391 } ,
392392 // 监听层级变化
@@ -521,6 +521,9 @@ export default {
521521 getThemeStyleId ( salt ) {
522522 return `t-theme-style-${ salt } `
523523 } ,
524+ parseNameHtmlSafely ( name ) {
525+ return name . replace ( / [ [ \] { } # \s \\ . , ; % * + = @ ! & ( ) / ] / g, '_' )
526+ } ,
524527 setTheme ( theme ) {
525528 let customThemes = getOptions ( ) . themes
526529 let themeStyle
@@ -535,10 +538,11 @@ export default {
535538 return
536539 }
537540 let css = themeStyle . match ( / ^ .* \{ ( .* ) } \s * $ / s) [ 1 ]
541+ let terminalName = this . parseNameHtmlSafely ( this . getName ( ) )
538542
539- themeStyle = `#t-${ this . getName ( ) } { ${ css } }`
543+ themeStyle = `#t-${ terminalName } { ${ css } }`
540544
541- let tagId = this . getThemeStyleId ( this . getName ( ) )
545+ let tagId = this . getThemeStyleId ( terminalName )
542546 let styleTag = document . getElementById ( tagId )
543547 if ( styleTag ) {
544548 styleTag . innerHTML = themeStyle
0 commit comments