File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -160,11 +160,17 @@ export default class XMLParser {
160160 ) {
161161 // Comment.
162162
163- currentNode . appendChild (
164- document . createComment (
165- Entities . decodeHTML ( ( match [ 6 ] ? '?' : '' ) + ( match [ 3 ] || match [ 4 ] || match [ 6 ] ) )
166- )
167- ) ;
163+ let comment : string ;
164+
165+ if ( match [ 3 ] ) {
166+ comment = match [ 3 ] ;
167+ } else if ( match [ 4 ] ) {
168+ comment = match [ 4 ] . endsWith ( '--' ) ? match [ 4 ] . slice ( 0 , - 2 ) : match [ 4 ] ;
169+ } else {
170+ comment = '?' + match [ 6 ] ;
171+ }
172+
173+ currentNode . appendChild ( document . createComment ( Entities . decodeHTML ( comment ) ) ) ;
168174 } else if ( match [ 5 ] ) {
169175 // Exclamation mark comment (usually <!DOCTYPE>).
170176
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import NamespaceURI from '../../src/config/NamespaceURI';
99import DocumentType from '../../src/nodes/document-type/DocumentType' ;
1010import XMLSerializer from '../../src/xml-serializer/XMLSerializer' ;
1111import IHTMLTemplateElement from '../../src/nodes/html-template-element/IHTMLTemplateElement' ;
12+ import NodeTypeEnum from '../../src/nodes/node/NodeTypeEnum' ;
1213
1314const GET_EXPECTED_HTML = ( html : string ) : string =>
1415 html
@@ -506,6 +507,13 @@ describe('XMLParser', () => {
506507 }
507508 } ) ;
508509
510+ it ( 'Parses comments with dash in them.' , ( ) => {
511+ const root = XMLParser . parse ( document , '<!-- comment with - in - it -->' ) ;
512+ expect ( root . childNodes . length ) . toBe ( 1 ) ;
513+ expect ( root . childNodes [ 0 ] . nodeType ) . toBe ( NodeTypeEnum . commentNode ) ;
514+ expect ( root . childNodes [ 0 ] . nodeValue ) . toBe ( ' comment with - in - it ' ) ;
515+ } ) ;
516+
509517 it ( 'Parses <template> elements, including its content.' , ( ) => {
510518 const root = XMLParser . parse ( document , '<div><template><tr><td></td></tr></template></div>' ) ;
511519 expect ( root . childNodes . length ) . toBe ( 1 ) ;
You can’t perform that action at this time.
0 commit comments