]> git.wincent.com - wikitext.git/commitdiff
Don't drop unexpected token on the floor after failed external link
authorWincent Colaiuta <win@wincent.com>
Fri, 5 Nov 2010 23:51:12 +0000 (00:51 +0100)
committerWincent Colaiuta <win@wincent.com>
Fri, 5 Nov 2010 23:51:12 +0000 (00:51 +0100)
This specifically arises after an EXT_LINK_START + PATH sequence. At
this point we expect a SPACE token, but if we don't get it, we were just
dropping it on the floor, which is bad.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
ext/parser.c
spec/regressions_spec.rb

index 57b4014fc55658a6a05a6266d75c4d7ebc035654..6b7c58e64d06ccbbe77ec590d91afc62f54d3610 100644 (file)
@@ -2054,6 +2054,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                             wiki_start_para_if_necessary(parser);
                             str_append(parser->output, ext_link_start, sizeof(ext_link_start) - 1);
                             str_append_str(parser->output, token_str);
+                            continue;
                         }
                     }
                     else
index bfb6dbfc5d53834b9c8cdde7cb43db76cc4fc797..ac03f6e59ef5521a1d0c8d0ee716cbbcc81971df 100644 (file)
@@ -864,4 +864,18 @@ describe Wikitext::Parser, 'regressions' do
     # and this one returned: <p><a href="/wiki/">foo</a></p>\n
     @parser.parse('[[  |foo]]').should == "<p>[[  |foo]]</p>\n"
   end
+
+  # first manifested itself in this comment: https://wincent.com/comments/6427
+  it 'handles "`[/`"' do
+    # This is, of course, an invalid link, but it could be handled more
+    # gracefully (we were opening a <code> span and instead of just rolling
+    # back the failed link and then proceeding with the parse and closing
+    # the span, we skipped the second backtick, causing the remainder of
+    # the input to appear inside the <code> span).
+    #
+    # Although the bug manifested itself with backticks, it could also have
+    # happened with any non-space token appearing after a EXT_LINK_START +
+    # PATH sequence (any such token would just be dropped on the floor).
+    @parser.parse('with `[/` then').should == "<p>with <code>[/</code> then</p>\n"
+  end
 end