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

Commit

Permalink
Merge pull request #100 from twitter/kl_autolink_urls_with_nested_parens
Browse files Browse the repository at this point in the history
Autolink URLs with nested parentheses.
  • Loading branch information
KL-7 committed Nov 13, 2013
2 parents cbab954 + 12e68cd commit 74697d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,3 +2,4 @@ language: ruby
rvm:
- 1.8.7
- 1.9.3
- 2.0.0
20 changes: 18 additions & 2 deletions lib/twitter-text/regex.rb
Expand Up @@ -221,10 +221,26 @@ 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
# Allow URL paths to contain balanced parens
# Allow URL paths to contain up to two nested levels of 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
# 3. Used in Rdio URLs like /track/We_Up_(Album_Version_(Edited))/
REGEXEN[:valid_url_balanced_parens] = /
\(
(?:
#{REGEXEN[:valid_general_url_path_chars]}+
|
# allow one nested level of balanced parentheses
(?:
#{REGEXEN[:valid_general_url_path_chars]}*
\(
#{REGEXEN[:valid_general_url_path_chars]}+
\)
#{REGEXEN[:valid_general_url_path_chars]}*
)
)
\)
/iox
# 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
Expand Down
2 changes: 1 addition & 1 deletion test/conformance_test.rb
Expand Up @@ -54,7 +54,7 @@ def self.def_conformance_test(file, test_type, &block)
raise "No such test suite: #{test_type.to_s}" unless yaml["tests"][test_type.to_s]

yaml["tests"][test_type.to_s].each do |test_info|
name = :"test_#{test_type}_#{test_info['description']}"
name = :"test_#{test_type} #{test_info['description']}"
define_method name do
@test_info = test_info
instance_eval(&block)
Expand Down
2 changes: 1 addition & 1 deletion test/twitter-text-conformance
Submodule twitter-text-conformance updated from 682d05 to 7ebf8f
2 changes: 1 addition & 1 deletion twitter-text.gemspec
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.summary = "Twitter text handling library"

s.add_development_dependency "multi_json", "~> 1.3"
s.add_development_dependency "nokogiri"
s.add_development_dependency "nokogiri", "~> 1.5.10"
s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
s.add_development_dependency "rspec"
Expand Down

0 comments on commit 74697d9

Please sign in to comment.