Skip to content

Commit

Permalink
fix false positive flagging of standalone autolinks as self-closing html
Browse files Browse the repository at this point in the history
fixes #208
  • Loading branch information
quantizor committed Aug 29, 2018
1 parent e3b39ca commit 3987668
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
36 changes: 36 additions & 0 deletions __snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3126,6 +3126,42 @@ exports[`markdown-to-jsx compiler links should handle autolink style 1`] = `
`;
exports[`markdown-to-jsx compiler links should handle autolinks after a paragraph (regression) 1`] = `
<div data-reactroot>
<p>
<strong>
autolink
</strong>
style
</p>
<p>
<a href="https://google.com">
https://google.com
</a>
</p>
</div>
`;
exports[`markdown-to-jsx compiler links should handle mailto autolinks after a paragraph 1`] = `
<div data-reactroot>
<p>
<strong>
autolink
</strong>
style
</p>
<p>
<a href="mailto:[email protected]">
[email protected]
</a>
</p>
</div>
`;
exports[`markdown-to-jsx compiler links should sanitize links containing JS expressions 1`] = `
<a data-reactroot>
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const HTML_COMMENT_R = /^<!--.*?-->/;
*/
const HTML_CUSTOM_ATTR_R = /^(data|aria|x)-[a-z_][a-z\d_.-]*$/;

const HTML_SELF_CLOSING_ELEMENT_R = /^ *<([A-Za-z][\w:]*)\s*((?:<.*?>|[^>])*)>(?!<\/\1>)\s*/;
const HTML_SELF_CLOSING_ELEMENT_R = /^ *<([A-Za-z][\w:]*)(?:\s+((?:<.*?>|[^>])*))?>(?!<\/\1>)\s*/;
const INTERPOLATION_R = /^\{.*\}$/;
const LINK_AUTOLINK_BARE_URL_R = /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/;
const LINK_AUTOLINK_MAILTO_R = /^<([^ >]+@[^ >]+)>/;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ export function compiler(markdown, options) {
order: PARSE_PRIORITY_HIGH,
parse(capture /*, parse, state*/) {
return {
attrs: attrStringToMap(capture[2]),
attrs: attrStringToMap(capture[2] || ''),
tag: capture[1],
};
},
Expand Down
24 changes: 24 additions & 0 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,30 @@ describe('markdown-to-jsx', () => {
expect(root.innerHTML).toMatchSnapshot();
});

it('should handle autolinks after a paragraph (regression)', () => {
render(
compiler(`
**autolink** style
<https://google.com>
`)
);

expect(root.innerHTML).toMatchSnapshot();
});

it('should handle mailto autolinks after a paragraph', () => {
render(
compiler(`
**autolink** style
<mailto:[email protected]>
`)
);

expect(root.innerHTML).toMatchSnapshot();
});

it('should handle a mailto autolink', () => {
render(compiler('<mailto:[email protected]>'));

Expand Down

0 comments on commit 3987668

Please sign in to comment.