Skip to content

Commit

Permalink
updated the url regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Gessler committed May 14, 2009
1 parent 18d0dae commit 0e35251
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion shorty.rb
Expand Up @@ -15,11 +15,23 @@
class Url
include DataMapper::Resource

IPv4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/ # 0-255
URL_REGEXP = %r{
\A
https?:// # http:// or https://
([^\s:@]+:[^\s:@]*@)? # optional username:pw@
( (xn--)?[^\W_]+([-.][^\W_]+)*\.[a-z]{2,6}\.? | # domain (including Punycode/IDN)...
#{IPv4_PART}(\.#{IPv4_PART}){3} ) # or IPv4
(:\d{1,5})? # optional port
([/?]\S*)? # optional /whatever or ?whatever
\Z
}iux

property :url, String, :length => 2024 # 2 kilobytes, thats one BIG url! Bigger than what IE can handle!
property :key, String, :index => true, :key => true, :length => 64

validates_present :url
validates_format :url, :as => :url
validates_format :url, :as => URL_REGEXP
validates_is_unique :key
validates_format :key, :as => /^[-_a-z0-9]+$/i # I only want to allow alpha, nums, _, and - in the URL key
end
Expand Down

0 comments on commit 0e35251

Please sign in to comment.