File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1- var attrRE = / ( [ \w - ] + ) | ( [ ' " ] ) ( [ . \s \S ] * ?) \2/ g;
1+ var attrRE = / ( [ \w - ] + ) | = | ( [ ' " ] ) ( [ . \s \S ] * ?) \2/ g;
22var voidElements = require ( 'void-elements' ) ;
33
44module . exports = function ( tag ) {
55 var i = 0 ;
66 var key ;
7+ var expectingValueAfterEquals = true ;
78 var res = {
89 type : 'tag' ,
910 name : '' ,
@@ -13,8 +14,17 @@ module.exports = function (tag) {
1314 } ;
1415
1516 tag . replace ( attrRE , function ( match ) {
16- if ( i % 2 ) {
17- key = match ;
17+ if ( match === '=' ) {
18+ expectingValueAfterEquals = true ;
19+ i ++ ;
20+ return ;
21+ }
22+
23+ if ( ! expectingValueAfterEquals ) {
24+ if ( key ) {
25+ res . attrs [ key ] = key ; // boolean attribute
26+ }
27+ key = match ;
1828 } else {
1929 if ( i === 0 ) {
2030 if ( voidElements [ match ] || tag . charAt ( tag . length - 2 ) === '/' ) {
@@ -23,9 +33,11 @@ module.exports = function (tag) {
2333 res . name = match ;
2434 } else {
2535 res . attrs [ key ] = match . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) ;
36+ key = undefined ;
2637 }
2738 }
2839 i ++ ;
40+ expectingValueAfterEquals = false ;
2941 } ) ;
3042
3143 return res ;
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ test('parseTag', function (t) {
6666 voidElement : false ,
6767 children : [ ]
6868 } ) ;
69-
69+
7070 tag = '<textarea placeholder=\'Hey Usher, \n\nAre these modals for real?!\' class=\'placeholder-value\'>' ;
7171
7272 t . deepEqual ( parseTag ( tag ) , {
@@ -80,5 +80,19 @@ test('parseTag', function (t) {
8080 children : [ ]
8181 } ) ;
8282
83+ tag = '<input checked name="sad" type="checkbox">' ;
84+
85+ t . deepEqual ( parseTag ( tag ) , {
86+ type : 'tag' ,
87+ attrs : {
88+ type : 'checkbox' ,
89+ checked : 'checked' ,
90+ name : 'sad'
91+ } ,
92+ name : 'input' ,
93+ voidElement : true ,
94+ children : [ ]
95+ } ) ;
96+
8397 t . end ( ) ;
8498} ) ;
You can’t perform that action at this time.
0 commit comments