Skip to content
This repository
Browse code

Updated domain regex to only allow underscores in subdomains

Updated Rakefile to include rubygems
  • Loading branch information...
commit b6a8310af250652509e00bd10fe5aad694ae741b 1 parent 5938d0f
J.P. Cummins authored
2  Gemfile.lock
... ... @@ -1,7 +1,7 @@
1 1 PATH
2 2 remote: .
3 3 specs:
4   - twitter-text (1.3.1)
  4 + twitter-text (1.3.2)
5 5 actionpack
6 6
7 7 GEM
2  Rakefile
@@ -39,7 +39,7 @@ namespace :test do
39 39
40 40 desc "Run conformance test suite"
41 41 task :run do
42   - ruby "test/conformance_test.rb"
  42 + ruby '-rubygems', "test/conformance_test.rb"
43 43 end
44 44 end
45 45
5 lib/regex.rb
@@ -54,7 +54,10 @@ class Regex
54 54
55 55 # URL related hash regex collection
56 56 REGEXEN[:valid_preceding_chars] = /(?:[^-\/"':!=A-Z0-9_@@]|^|\:)/i
57   - REGEXEN[:valid_domain] = /(?:[^[:punct:]\s][\._-](?=[^[:punct:]\s])|[^[:punct:]\s]){1,}\.[a-z]{2,}(?::[0-9]+)?/i
  57 +
  58 + REGEXEN[:valid_subdomain] = /([^[:punct:]\s]([_-]|[^[:punct:]\s])*)?[^[:punct:]\s]\./
  59 + REGEXEN[:valid_domain_name] = /([^[:punct:]\s]([-]|[^[:punct:]\s])*)?[^[:punct:]\s]/
  60 + REGEXEN[:valid_domain] = /#{REGEXEN[:valid_subdomain]}*#{REGEXEN[:valid_domain_name]}\.[a-z]{2,}(?::[0-9]+)?/i
58 61
59 62 REGEXEN[:valid_general_url_path_chars] = /[a-z0-9!\*';:=\+\,\$\/%#\[\]\-_~]/i
60 63 # Allow URL paths to contain balanced parens
15 spec/test_urls.rb
@@ -22,6 +22,10 @@ module TestUrls
22 22 "http://x.com/has/one/char/domain",
23 23 "http://t.co/nwcLTFF",
24 24 "http://sub_domain-dash.twitter.com",
  25 + "http://a.b.cd",
  26 + "http://a_b.c-d.com",
  27 + "http://a-b.b.com",
  28 + "http://twitter-dash.com",
25 29 # "t.co/nwcLTFF"
26 30 ] unless defined?(TestUrls::VALID)
27 31
@@ -30,7 +34,16 @@ module TestUrls
30 34 "http://tld-too-short.x",
31 35 "www.foobar.com",
32 36 "WWW.FOOBAR.COM",
33   - "http://-doman_dash.com"
  37 + "http://-doman_dash.com",
  38 + "http://_leadingunderscore.twitter.com",
  39 + "http://trailingunderscore_.twitter.com",
  40 + "http://-leadingdash.twitter.com",
  41 + "http://trailingdash-.twitter.com",
  42 + "http://-leadingdash.com",
  43 + "http://trailingdash-.com",
  44 + "http://no_underscores.com",
  45 + "http://test.c_o_m",
  46 + "http://test.c-o-m"
34 47 ] unless defined?(TestUrls::INVALID)
35 48
36 49 end

0 comments on commit b6a8310

Please sign in to comment.
Something went wrong with that request. Please try again.