]> git.wincent.com - wikitext.git/commitdiff
Pass through zero-length image targets unchanged
authorWincent Colaiuta <win@wincent.com>
Wed, 6 May 2009 21:54:12 +0000 (23:54 +0200)
committerWincent Colaiuta <win@wincent.com>
Wed, 6 May 2009 21:54:12 +0000 (23:54 +0200)
That is, "{{}}" should not be turned into an "img" tag.

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

index 2170535ebd5437bbf7bf2dc55b25a6f1c1226625..90a13891bd3e2ee1ac4a17c556cc89e620cecfb1 100644 (file)
@@ -2416,14 +2416,14 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                     {
                         if (type == PATH || type == PRINTABLE || type == ALNUM || type == SPECIAL_URI_CHARS)
                             rb_str_cat(parser->link_target, token->start, TOKEN_LEN(token));
-                        else if (type == IMG_END)
+                        else if (type == IMG_END && RSTRING_LEN(parser->link_target) > 0)
                         {
                             // success
                             _Wikitext_append_img(parser, RSTRING_PTR(parser->link_target), RSTRING_LEN(parser->link_target));
                             token = NULL;
                             break;
                         }
-                        else // unexpected token (syntax error)
+                        else // unexpected token or zero-length target (syntax error)
                         {
                             // rollback
                             rb_str_cat(parser->output, literal_img_start, sizeof(literal_img_start) - 1);
index 5757ca745e65076fed6ea92c7ffec9f833a24a22..03fac30cbc87e040352da41ad49fce91c99392da 100644 (file)
@@ -43,6 +43,10 @@ describe Wikitext::Parser, 'embedding img tags' do
     @parser.parse('{{foo/bar.png}}').should == %Q{<p><img src="/images/foo/bar.png" alt="foo/bar.png" /></p>\n}
   end
 
+  it 'should pass through empty image tags unchanged' do
+    @parser.parse('{{}}').should == %Q{<p>{{}}</p>\n}
+  end
+
   it 'should work in BLOCKQUOTE blocks' do
     expected = dedent <<-END
       <blockquote>