File tree Expand file tree Collapse file tree 2 files changed +5
-16
lines changed Expand file tree Collapse file tree 2 files changed +5
-16
lines changed Original file line number Diff line number Diff line change
1
+ var _ = require ( 'lodash' ) ;
2
+
1
3
/**
2
4
* Serializes HTML elements back to raw HTML
3
5
*/
4
-
5
6
module . exports = {
6
7
/**
7
8
* @param {String } name
@@ -37,7 +38,7 @@ module.exports = {
37
38
var res = '<' + tagName ;
38
39
39
40
attrs . forEach ( function ( attr ) {
40
- res += ' ' + attr . name + '="' + escape ( attr . value ) + '"' ;
41
+ res += ' ' + attr . name + '="' + _ . escape ( attr . value ) + '"' ;
41
42
} ) ;
42
43
43
44
selfClosing && ( res += '/' ) ;
@@ -56,7 +57,7 @@ module.exports = {
56
57
* @returns {String }
57
58
*/
58
59
text : function ( text ) {
59
- return text ;
60
+ return _ . escape ( text ) ;
60
61
} ,
61
62
/**
62
63
* @param {String } text
@@ -66,15 +67,3 @@ module.exports = {
66
67
return '<!--' + text + '-->' ;
67
68
}
68
69
} ;
69
-
70
- /**
71
- * @param {String } str
72
- * @returns {String }
73
- */
74
- function escape ( str ) {
75
- return String ( str )
76
- . replace ( / & / g, '&' )
77
- . replace ( / " / g, '"' )
78
- . replace ( / < / g, '<' )
79
- . replace ( / > / g, '>' ) ;
80
- }
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ describe('\'serialize\'', function () {
63
63
it ( 'must serialize text' , function ( ) {
64
64
var output = '\nblah\t"' ;
65
65
66
- serialize . text ( '\nblah\t" ' ) . must . be . equal ( output ) ;
66
+ serialize . text ( '\nblah\t" ' ) . must . be . equal ( output ) ;
67
67
} ) ;
68
68
69
69
it ( 'must serialize comments' , function ( ) {
You can’t perform that action at this time.
0 commit comments