Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<foo> is parsed as HTML element even if < is escaped with \ #1140

Closed
rhysd opened this issue Mar 13, 2018 · 0 comments · Fixed by #1135
Closed

<foo> is parsed as HTML element even if < is escaped with \ #1140

rhysd opened this issue Mar 13, 2018 · 0 comments · Fixed by #1135

Comments

@rhysd
Copy link

rhysd commented Mar 13, 2018

Marked version: 0.3.17

Markdown flavor: CommonMark or GitHub Flavored Markdown

Expectation

Parsed as text and it should not be sanitized

Result

Parsed as HTML tag and it is passed to a sanitizer

What was attempted

Install marked with npm install marked.

Then put following code as foo.js

const marked = require('marked');

const doc = '\\<div>';

console.log(
    marked(doc, {
        sanitize: true,
        sanitizer: tag => {
            console.log('tag:', tag);
            return tag;
        },
    }),
);

Finally run it with node foo.js.

It outputs:

tag: <div>
<p>\<div></p>

The <div> just after \ is parsed as <div> HTML element even if < is escaped with \. However, as long as I confirmed with http://spec.commonmark.org/dingus/, \<div> should be parsed as text '<div>'. So it should not be passed to sanitizer and should be escaped as \&lt;div&gt; by marked.

I have trouble with this problem because sanitizer cannot know whether the input is just a text input (where < is escaped with \) or actual HTML tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant