Skip to content

Commit

Permalink
Fix HTML multiline comments bug (quantizor#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
eragon512 committed Sep 11, 2019
1 parent ce11e49 commit 5aa8010
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions index.compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,21 @@ describe('arbitrary HTML', () => {
Foo
</p>
`);
});

it('throws out multiline HTML comments', () => {
render(compiler(`Foo\n<!-- this is
a
multiline
comment -->`));

expect(root.innerHTML).toMatchInlineSnapshot(`
<p data-reactroot>
Foo
</p>
`);
});

Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@ export function compiler(markdown, options) {
: undefined;
}

function stripHtmlComments(html) {
return html.replace(/<!--[\s\S]*?(?:-->)/g, '')
}

/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production') {
if (typeof markdown !== 'string') {
Expand Down Expand Up @@ -1552,7 +1556,7 @@ export function compiler(markdown, options) {
const parser = parserFor(rules);
const emitter = reactFor(ruleOutput(rules));

const jsx = compile(markdown);
const jsx = compile(stripHtmlComments(markdown));

if (footnotes.length) {
jsx.props.children.push(
Expand Down

0 comments on commit 5aa8010

Please sign in to comment.