]> git.wincent.com - wikitext.git/commitdiff
Don't apply "external" class when rolling back failed external links
authorWincent Colaiuta <win@wincent.com>
Fri, 8 May 2009 11:56:24 +0000 (13:56 +0200)
committerWincent Colaiuta <win@wincent.com>
Fri, 8 May 2009 11:56:24 +0000 (13:56 +0200)
We were incorrectly applying the "external" CSS class when rolling back
failed external links (eg. '[/hello this').

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

index 7ef539591e00633b1199be4f5b049da8ed530589..e51b98e9a4b75d39c0fad2f33cb7ad7767329238 100644 (file)
@@ -908,12 +908,16 @@ void _Wikitext_rollback_failed_external_link(parser_t *parser)
 {
     if (!IN(EXT_LINK_START))
         return; // nothing to do!
-    int scope_includes_space = IN(SPACE); // remember this before popping
+    int scope_includes_space = IN(SPACE); // remember these before popping
+    int scope_includes_path  = IN(PATH);
     _Wikitext_pop_from_stack_up_to(parser, Qnil, EXT_LINK_START, Qtrue);
     rb_str_cat(parser->output, ext_link_start, sizeof(ext_link_start) - 1);
     if (!NIL_P(parser->link_target))
     {
-        _Wikitext_append_hyperlink(parser, Qnil, parser->link_target, parser->link_target, parser->external_link_class, Qtrue);
+        if (scope_includes_path) // don't use external link class
+            _Wikitext_append_hyperlink(parser, Qnil, parser->link_target, parser->link_target, Qnil, Qtrue);
+        else
+            _Wikitext_append_hyperlink(parser, Qnil, parser->link_target, parser->link_target, parser->external_link_class, Qtrue);
         if (scope_includes_space)
         {
             rb_str_cat(parser->output, space, sizeof(space) - 1);
index f6d51a68629d20b1a1dad8c5c5d063f76d462441..d3a72f08da798303d2524127bcf22df2cb6eebfb 100755 (executable)
@@ -326,4 +326,21 @@ describe Wikitext::Parser, 'external links' do
       @parser.parse("> [http://google.com/\n").should == expected # was a bug
     end
   end
+
+  describe 'regressions' do
+    # assorted examples
+    it 'should not turn failed absolute links into external hyperlinks' do
+      # was emitting: <p>[<a href="/hello" class="external">/hello</a> this</p>\n
+      expected =   %Q{<p>[<a href="/hello">/hello</a> this</p>\n}
+      @parser.parse('[/hello this').should == expected
+
+      # was emitting: <p>[<a href="/hello" class="external">/hello</a> </p>\n
+      expected =   %Q{<p>[<a href="/hello">/hello</a> </p>\n}
+      @parser.parse('[/hello ').should == expected
+
+      # was emitting: <h1>hello [<a href="/hello" class="external">/hello</a> </h1>\n
+      expected =   %Q{<h1>hello [<a href="/hello">/hello</a> </h1>\n}
+      @parser.parse('= hello [/hello =').should == expected
+    end
+  end
 end