From c18a908e6887b384c2d42badfd0523f11f88e0d7 Mon Sep 17 00:00:00 2001 From: Eric Marden Date: Mon, 30 Sep 2013 15:44:49 -0500 Subject: [PATCH] uses a more RFC2396 complaint regex pattern The current regex pattern was tripping on a number of valid URLs, so this change updates it to use the URI module's regexp class. To maintain some compatability with the old regex, I have limited the valid urls accepted by this regex to the http and https schemes. --- lib/data_mapper/validation/rule/formats/url.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/data_mapper/validation/rule/formats/url.rb b/lib/data_mapper/validation/rule/formats/url.rb index bfad5570..4d11ca48 100644 --- a/lib/data_mapper/validation/rule/formats/url.rb +++ b/lib/data_mapper/validation/rule/formats/url.rb @@ -1,13 +1,14 @@ # encoding: utf-8 +require 'uri' + module DataMapper module Validation class Rule module Formats - # Regex from http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/ Url = begin - /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((\:[0-9]{1,5})?\/?.*)?$)/ix + URI.regexp(['http','https']) end end # module Formats