Skip to content

Commit

Permalink
Fix HTML multiline comments bug (#246) (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
eragon512 authored and quantizor committed Sep 12, 2019
1 parent d2d5271 commit 7b55be6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"size-limit": [
{
"path": "dist/cjs.js",
"limit": "5.15 kB"
"limit": "5.25 kB"
}
],
"jest": {
Expand Down

0 comments on commit 7b55be6

Please sign in to comment.