File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ module.exports = class XMLStringifier
162
162
# `str` the string to escape
163
163
textEscape : (str ) ->
164
164
if @options .noValidation then return str
165
- ampregex = if @options .noDoubleEncoding then / (?!&\S + ;)&/g else / & / g
165
+ ampregex = if @options .noDoubleEncoding then / (?!&(lt | gt | amp | apos | quot) ;)&/g else / & / g
166
166
str .replace (ampregex, ' &' )
167
167
.replace (/ </ g , ' <' )
168
168
.replace (/ >/ g , ' >' )
@@ -175,7 +175,7 @@ module.exports = class XMLStringifier
175
175
# `str` the string to escape
176
176
attEscape : (str ) ->
177
177
if @options .noValidation then return str
178
- ampregex = if @options .noDoubleEncoding then / (?!&\S + ;)&/g else / & / g
178
+ ampregex = if @options .noDoubleEncoding then / (?!&(lt | gt | amp | apos | quot) ;)&/g else / & / g
179
179
str .replace (ampregex, ' &' )
180
180
.replace (/ </ g , ' <' )
181
181
.replace (/ "/ g , ' "' )
Original file line number Diff line number Diff line change 1
1
obj =
2
2
root :
3
- ' @att' : ' attribute value with &num ; and # ;'
4
- ' #text' : ' HTML entities for umlaut are ü ; and ü ;.'
3
+ ' @att' : ' attribute value with & ; and & ;'
4
+ ' #text' : ' XML entities for ampersand are & ; and & ;.'
5
5
6
6
suite ' Tests specific to issues:' , ->
7
7
test ' Issue #97 (No double encoding)' , ->
8
8
eq (
9
9
xml (obj, { noDoubleEncoding : true }).end ()
10
10
' <?xml version="1.0"?>' +
11
- ' <root att="attribute value with &num ; and # ;">' +
12
- ' HTML entities for umlaut are ü ; and ü ;.' +
11
+ ' <root att="attribute value with & ; and &#38 ;">' +
12
+ ' XML entities for ampersand are & ; and &#38 ;.' +
13
13
' </root>'
14
14
)
15
15
16
16
test ' Issue #97 (Double encoding - default behavior)' , ->
17
17
eq (
18
18
xml (obj).end ()
19
19
' <?xml version="1.0"?>' +
20
- ' <root att="attribute value with &num ; and &#35 ;">' +
21
- ' HTML entities for umlaut are &uuml ; and &#252 ;.' +
20
+ ' <root att="attribute value with &amp ; and &#38 ;">' +
21
+ ' XML entities for ampersand are &amp ; and &#38 ;.' +
22
22
' </root>'
23
23
)
24
24
You can’t perform that action at this time.
0 commit comments