diff --git a/lib/scrivener/validations.rb b/lib/scrivener/validations.rb index 5d33ff7..a589f9e 100644 --- a/lib/scrivener/validations.rb +++ b/lib/scrivener/validations.rb @@ -1,4 +1,5 @@ class Scrivener + require "uri" # Provides a base implementation for extensible validation routines. # {Scrivener::Validations} currently only provides the following assertions: @@ -130,9 +131,7 @@ def assert_numeric(att, error = [att, :not_numeric]) end end - URL = /\A(http|https):\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|(2 - 5[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3} - |localhost)(:[0-9]{1,5})?(\/.*)?\z/ix + URL = URI::regexp(%w(http https)) def assert_url(att, error = [att, :not_url]) if assert_present(att, error) diff --git a/test/scrivener_test.rb b/test/scrivener_test.rb index 9704092..a911052 100644 --- a/test/scrivener_test.rb +++ b/test/scrivener_test.rb @@ -115,6 +115,10 @@ def validate p = Post.new(url: "http://google.com", email: "me@google.com") assert p.valid? + + # server name without a / but a ? is a valid URL + p = Post.new(url: "http://google.com?blah=blah", email: "me@google.com") + assert p.valid? end end