Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed URL to use Ruby's standard URI regex #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drpentode
Copy link

Removed custom URL regex and used standard regex provided by Ruby for more consistent URL matching. Test case included in test/scrivener_test.rb.

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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about this. Very cool!

@foca
Copy link
Contributor

foca commented May 4, 2016

bump

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to pass the schemes here:

def assert_url(att, schemes = %w(http https), error = [att, :not_url])
  if assert_present(att, error)
    assert_format(att, URI.regexp(schemes), error)
  end
end

This would allow people to use this helper to check other kind of URLs without extra work. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants