Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
allow @ in url
Browse files Browse the repository at this point in the history
  • Loading branch information
jakl committed Feb 26, 2013
1 parent 93ae21c commit 4117b58
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions lib/twitter-text/regex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,23 @@ def self.regex_range(from, to = nil) # :nodoc:

REGEXEN[:valid_port_number] = /[0-9]+/

REGEXEN[:valid_general_url_path_chars] = /[a-z0-9!\*';:=\+\,\.\$\/%#\[\]\-_~&|#{LATIN_ACCENTS}]/io
REGEXEN[:valid_general_url_path_chars] = /[a-z0-9!\*';:=\+\,\.\$\/%#\[\]\-_~&|@#{LATIN_ACCENTS}]/io
# Allow URL paths to contain balanced parens
# 1. Used in Wikipedia URLs like /Primer_(film)
# 2. Used in IIS sessions like /S(dfd346)/
REGEXEN[:valid_url_balanced_parens] = /\(#{REGEXEN[:valid_general_url_path_chars]}+\)/io
# Valid end-of-path chracters (so /foo. does not gobble the period).
# 1. Allow =&# for empty URL parameters and other URL-join artifacts
REGEXEN[:valid_url_path_ending_chars] = /[a-z0-9=_#\/\+\-#{LATIN_ACCENTS}]|(?:#{REGEXEN[:valid_url_balanced_parens]})/io
# Allow @ in a url, but only in the middle. Catch things like http://example.com/@user/
REGEXEN[:valid_url_path] = /(?:
(?:
#{REGEXEN[:valid_general_url_path_chars]}*
(?:#{REGEXEN[:valid_url_balanced_parens]} #{REGEXEN[:valid_general_url_path_chars]}*)*
#{REGEXEN[:valid_url_path_ending_chars]}
)|(?:@#{REGEXEN[:valid_general_url_path_chars]}+\/)
)|(?:#{REGEXEN[:valid_general_url_path_chars]}+\/)
)/iox

REGEXEN[:valid_url_query_chars] = /[a-z0-9!?\*'\(\);:&=\+\$\/%#\[\]\-_\.,~|]/i
REGEXEN[:valid_url_query_chars] = /[a-z0-9!?\*'\(\);:&=\+\$\/%#\[\]\-_\.,~|@]/i
REGEXEN[:valid_url_query_ending_chars] = /[a-z0-9_&=#\/]/i
REGEXEN[:valid_url] = %r{
( # $1 total match
Expand Down
5 changes: 2 additions & 3 deletions spec/autolinking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,8 @@ def original_text; 'http://x.xx.com/@"style="color:pink"onmouseover=alert(1)//';
context "with a username not followed by a /" do
def original_text; 'http://example.com/@foobar'; end

it "should link small url and username" do
@autolinked_text.should have_autolinked_url('http://example.com/')
@autolinked_text.should link_to_screen_name('foobar')
it "should link url" do
@autolinked_text.should have_autolinked_url('http://example.com/@foobar')
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/rewriter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ def original_text; 'http://x.xx.com/@"style="color:pink"onmouseover=alert(1)//';
context "with a username not followed by a /" do
def original_text; "http://example.com/@foobar"; end

it "should link small url and username" do
@block_args.should == ["http://example.com/"]
@rewritten_text.should == "[rewritten]@foobar"
it "should link url" do
@block_args.should == ["http://example.com/@foobar"]
@rewritten_text.should == "[rewritten]"
end
end

Expand Down

0 comments on commit 4117b58

Please sign in to comment.