@@ -37,12 +37,13 @@ export default class EntitiesParser{
3737 }
3838 addExternalEntity ( key , val ) {
3939 validateEntityName ( key ) ;
40+ const escaped = key . replace ( / [ . \- + * : ] / g, '\\.' ) ;
4041 if ( val . indexOf ( "&" ) !== - 1 ) {
4142 reportWarning ( `Entity ${ key } is not added as '&' is found in value;` )
4243 return ;
4344 } else {
44- this . lastEntities [ ent ] = {
45- regex : new RegExp ( "&" + key + ";" , "g" ) ,
45+ this . lastEntities [ key ] = {
46+ regex : new RegExp ( "&" + escaped + ";" , "g" ) ,
4647 val : val
4748 }
4849 }
@@ -52,8 +53,9 @@ export default class EntitiesParser{
5253 const entKeys = Object . keys ( entities ) ;
5354 for ( let i = 0 ; i < entKeys . length ; i ++ ) {
5455 const ent = entKeys [ i ] ;
56+ const escaped = ent . replace ( / [ . \- + * : ] / g, '\\.' ) ;
5557 this . docTypeEntities [ ent ] = {
56- regex : new RegExp ( "&" + ent + ";" , "g" ) ,
58+ regex : new RegExp ( "&" + escaped + ";" , "g" ) ,
5759 val : entities [ ent ]
5860 }
5961 }
@@ -89,11 +91,11 @@ export default class EntitiesParser{
8991 }
9092 return val ;
9193 }
92- } ;
94+ }
9395
9496//an entity name should not contains special characters that may be used in regex
9597//Eg !?\\\/[]$%{}^&*()<>
96- const specialChar = "!?\\\ /[]$%{}^&*()<>|+" ;
98+ const specialChar = "!?\\/[]$%{}^&*()<>|+" ;
9799
98100function validateEntityName ( name ) {
99101 for ( let i = 0 ; i < specialChar . length ; i ++ ) {
0 commit comments