Browse Source

Forbid nested reference links

pull/14/head
Alex Kocharin 10 years ago
parent
commit
6d4538910c
  1. 5
      lib/rules_inline/links.js
  2. 1
      lib/rules_inline/state_inline.js
  3. 17
      test/fixtures/stmd/bad.txt
  4. 12
      test/fixtures/stmd/good.txt

5
lib/rules_inline/links.js

@ -95,6 +95,9 @@ function links(state) {
// Link reference // Link reference
// //
// do not allow nested reference links
if (state.linkLevel > 0) { return false; }
// [foo] [bar] // [foo] [bar]
// ^^ optional whitespace (can include newlines) // ^^ optional whitespace (can include newlines)
for (; pos < max; pos++) { for (; pos < max; pos++) {
@ -147,7 +150,9 @@ function links(state) {
title: title, title: title,
level: state.level++ level: state.level++
}); });
state.linkLevel++;
state.parser.tokenize(state); state.parser.tokenize(state);
state.linkLevel--;
state.push({ type: 'link_close', level: --state.level }); state.push({ type: 'link_close', level: --state.level });
} }

1
lib/rules_inline/state_inline.js

@ -14,6 +14,7 @@ function StateInline(src, parser, options, env) {
this.posMax = this.src.length; this.posMax = this.src.length;
this.validateInsideEm = false; this.validateInsideEm = false;
this.validateInsideLink = false; this.validateInsideLink = false;
this.linkLevel = 0;
this.level = 0; this.level = 0;
this.link_content = ''; this.link_content = '';
this.pendingLevel = 0; this.pendingLevel = 0;

17
test/fixtures/stmd/bad.txt

@ -1,20 +1,3 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 5169
.
[[[foo]]]
[[[foo]]]: /url1
[foo]: /url2
.
<p><a href="/url1">[[foo]]</a></p>
.
error:
<p><a href="/url1">[<a href="/url2">foo</a>]</a></p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 5248 src line: 5248

12
test/fixtures/stmd/good.txt

@ -4561,6 +4561,18 @@ src line: 5161
<p><a href="/url">[[foo]]</a></p> <p><a href="/url">[[foo]]</a></p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 5169
.
[[[foo]]]
[[[foo]]]: /url1
[foo]: /url2
.
<p><a href="/url1">[[foo]]</a></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 5180 src line: 5180

Loading…
Cancel
Save