Skip to content

Commit

Permalink
Merge pull request #977 from KostyaTretyak/parser-fix
Browse files Browse the repository at this point in the history
Parser fix
  • Loading branch information
joshbruce committed Jan 5, 2018
2 parents 6657cec + 13e97eb commit 08d2512
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/marked.js
Expand Up @@ -445,9 +445,9 @@ Lexer.prototype.token = function(src, top, bq) {

var inline = {
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
autolink: /^<([^ <>]+(@|:\/)[^ <>]+)>/,
url: noop,
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^<'">])*?>/,
link: /^!?\[(inside)\]\(href\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
Expand Down
22 changes: 17 additions & 5 deletions test/tests/auto_links.html
@@ -1,18 +1,30 @@
<p>Link: <a href="http://example.com/">http://example.com/</a>.</p>

<p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
<p>With an ampersand: <a href="http://example1.com/?foo=1&amp;bar=2">http://example1.com/?foo=1&amp;bar=2</a></p>

<ul>
<li>In a list?</li>
<li><a href="http://example.com/">http://example.com/</a></li>
<li><a href="http://example2.com/">http://example2.com/</a></li>
<li>It should.</li>
</ul>

<blockquote>
<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
<p>Blockquoted: <a href="http://example3.com/">http://example3.com/</a></p>
</blockquote>

<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
<p>Auto-links should not occur here: <code>&lt;http://example4.com/&gt;</code></p>

<pre><code>or here: &lt;http://example.com/&gt;
<pre><code>or here: &lt;http://example5.com/&gt;
</code></pre>

<p>Open angle bracket with link:</p>

<p>&lt;<a href="http://example6.com">http://example6.com</a></p>

<p>With space: &lt; <a href="http://example7.com">http://example7.com</a></p>

<p>With content: &lt;1 <a href="http://example8.com">http://example8.com</a></p>

<p>hello world
<a href="http://example9.com">http://example9.com</a>
</p>
21 changes: 16 additions & 5 deletions test/tests/auto_links.text
@@ -1,13 +1,24 @@
Link: <http://example.com/>.

With an ampersand: <http://example.com/?foo=1&bar=2>
With an ampersand: <http://example1.com/?foo=1&bar=2>

* In a list?
* <http://example.com/>
* <http://example2.com/>
* It should.

> Blockquoted: <http://example.com/>
> Blockquoted: <http://example3.com/>

Auto-links should not occur here: `<http://example.com/>`
Auto-links should not occur here: `<http://example4.com/>`

or here: <http://example.com/>
or here: <http://example5.com/>

Open angle bracket with link:

<<http://example6.com>

With space: < <http://example7.com>

With content: <1 <http://example8.com>

hello world
<http://example9.com>
2 changes: 1 addition & 1 deletion test/tests/mangle_xss.sanatize.nomangle.html
@@ -1,3 +1,3 @@
<p><a href="mailto:&lt;svg/onload=&quot;alert(1)&quot;//@x">&lt;svg/onload=&quot;alert(1)&quot;//@x</a></p>
<p>&lt;<a href="mailto:svg/onload=&quot;alert(1)&quot;//@x">svg/onload=&quot;alert(1)&quot;//@x</a></p>

<p><a href="mailto:bar&quot;onclick=&quot;alert(&#39;XSS&#39;)&quot;@foo">bar&quot;onclick=&quot;alert(&#39;XSS&#39;)&quot;@foo</a></p>

0 comments on commit 08d2512

Please sign in to comment.