Permalink
Browse files

Automatically assume the scheme of http if none is provided

  • Loading branch information...
1 parent c660329 commit ff12a6743e8c62e832f9c1674080d291da6bb35c @nathanbertram committed Jul 6, 2011
Showing with 6 additions and 4 deletions.
  1. +3 −1 lib/validate_url.rb
  2. +3 −3 spec/validate_url_spec.rb
View
@@ -13,7 +13,9 @@ def initialize(options)
def validate_each(record, attribute, value)
schemes = [*options.fetch(:schemes)].map(&:to_s)
-
+
+ value = "http://#{value}" unless value =~ /:\/\// || value !~ /[.]/
+
if URI::regexp(schemes).match(value)
begin
URI.parse(value)
@@ -31,11 +31,11 @@
@user.should_not be_valid
end
- it "should not allow an url without scheme" do
+ it "should allow an url without scheme and assume it's http" do
@user.homepage = "www.example.com"
- @user.should_not be_valid
+ @user.should be_valid
end
-
+
it "should allow an url with http" do
@user.homepage = "http://localhost"
@user.should be_valid

1 comment on commit ff12a67

Owner

nathanbertram commented on ff12a67 Jul 6, 2011

Now that I think about it.. This was a really bad idea :-)

Please sign in to comment.