urls_fix.patch

Paul Rivier, 2008-08-26 12:01

Download (4.37 KB)

View differences:

lib/redcloth.rb Tue Aug 26 12:02:05 2008 +0200
788 788
            ":
789 789
            ([\w\/]\S+?)               # $url
790 790
            (\/)?                      # $slash
791
            ([^\w\/;]*?)               # $post
791
            ([^\w\=\/;\(\)]*?)         # $post
792 792
            (?=<|\s|$)
793 793
        /x 
794

  
794
#"
795 795
    def inline_textile_link( text ) 
796 796
        text.gsub!( LINK_RE ) do |m|
797 797
            pre,atts,text,title,url,slash,post = $~[1..7]
......
799 799
            url, url_title = check_refs( url )
800 800
            title ||= url_title
801 801
            
802
            # Idea below : an URL with unbalanced parethesis and
803
            # ending by ')' is put into external parenthesis
804
            if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) )
805
              url=url[0..-2] # discard closing parenth from url
806
              post = ")"+post # add closing parenth to post
807
            end
802 808
            atts = pba( atts )
803 809
            atts = " href=\"#{ url }#{ slash }\"#{ atts }"
804 810
            atts << " title=\"#{ title }\"" if title
lib/redmine/wiki_formatting.rb Tue Aug 26 12:02:05 2008 +0200
144 144
                          (\S+?)                   # url
145 145
                          (\/)?                    # slash
146 146
                        )
147
                        ([^\w\=\/;]*?)               # post
147
                        ([^\w\=\/;\(\)]*?)               # post
148 148
                        (?=<|\s|$)
149 149
                       }x unless const_defined?(:AUTO_LINK_RE)
150 150

  
......
156 156
            # don't replace URL's that are already linked
157 157
            # and URL's prefixed with ! !> !< != (textile images)
158 158
            all
159
          else            
159
          else
160
            # Idea below : an URL with unbalanced parethesis and
161
            # ending by ')' is put into external parenthesis
162
            if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) )
163
              url=url[0..-2] # discard closing parenth from url
164
              post = ")"+post # add closing parenth to post
165
            end
160 166
            %(#{leading}<a class="external" href="#{proto=="www."?"http://www.":proto}#{url}">#{proto + url}</a>#{post})
161 167
          end
162 168
        end
test/unit/helpers/application_helper_test.rb Tue Aug 26 12:02:05 2008 +0200
38 38
      'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.',
39 39
      'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).',
40 40
      'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
41
      'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>',
42
      '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)',
43
      '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)',
41 44
      'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
42 45
      'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
43 46
      'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>',
44 47
      'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>',
48
      'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>',
45 49
      'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>',
46 50
    }
47 51
    to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }