From 0e352515ee11a617f9da79c8850c9f60bd941003 Mon Sep 17 00:00:00 2001 From: Brad Gessler Date: Thu, 14 May 2009 02:10:39 -0500 Subject: [PATCH] updated the url regexp --- shorty.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/shorty.rb b/shorty.rb index bbaf95d..aa0634a 100644 --- a/shorty.rb +++ b/shorty.rb @@ -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