Skip to content

Commit

Permalink
Skip all non-text, non-element nodes in SectionParser
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Jan 28, 2016
1 parent 6f5033d commit 4d5b4d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/js/parsers/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ export default class SectionParser {
case NODE_TYPES.ELEMENT:
this.parseElementNode(node);
break;
default:
assert(`parseNode got unexpected element type ${node.nodeType} ` + node,
false);
}
}

Expand Down
15 changes: 14 additions & 1 deletion tests/unit/parsers/section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test('#parse skips STYLE nodes', (assert) => {
assert.equal(sections.length, 0, 'does not parse style');
});

test('#parse skips Comment nodes', (assert) => {
test('#parse skips top-level Comment nodes', (assert) => {
let element = buildDOM(`
<!--Some comment-->
`).firstChild;
Expand All @@ -171,3 +171,16 @@ test('#parse skips Comment nodes', (assert) => {

assert.equal(sections.length, 0, 'does not parse comments');
});

test('#parse skips nested Comment nodes', (assert) => {
let element = buildDOM(`
<p><!--Some comment-->some text<!-- another comment --></p>
`).firstChild;
parser = new SectionParser(builder);
let sections = parser.parse(element);

assert.equal(sections.length, 1);
let section = sections[0];
assert.equal(section.text, 'some text', 'parses text surrounded by comments');
assert.equal(section.markers.length, 1, 'only 1 marker');
});

0 comments on commit 4d5b4d2

Please sign in to comment.