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

#valid? doesn't work for protocol-less urls #55

Closed
walro opened this issue Oct 29, 2015 · 0 comments · Fixed by #58
Closed

#valid? doesn't work for protocol-less urls #55

walro opened this issue Oct 29, 2015 · 0 comments · Fixed by #58
Labels

Comments

@walro
Copy link
Contributor

walro commented Oct 29, 2015

irb(main):001:0> Twingly::URL.parse("//www.url.com")
=> #<Twingly::URL:0x3fd8a893c950 //www.url.com>
irb(main):002:0> Twingly::URL.parse("//www.url.com").valid?
NoMethodError: undefined method `downcase' for nil:NilClass
    from /Users/robin/Workspace/git/twingly-url/lib/twingly/url.rb:103:in `normalized_scheme'
    from /Users/robin/Workspace/git/twingly-url/lib/twingly/url.rb:126:in `valid?'
    from (irb):2
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/cli/console.rb:14:in `run'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/cli.rb:308:in `console'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/cli.rb:10:in `start'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/bin/bundle:20:in `block in <top (required)>'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/lib/bundler/friendly_errors.rb:7:in `with_friendly_errors'
    from /Users/robin/.gem/ruby/2.2.3/gems/bundler-1.10.6/bin/bundle:18:in `<top (required)>'
    from /Users/robin/.gem/ruby/2.2.3/bin/bundle:23:in `load'
    from /Users/robin/.gem/ruby/2.2.3/bin/bundle:23:in `<main>'

I think we can just switch the order of our if statements

Edit: or not, we need to do something else :)

@walro walro added the bug label Oct 29, 2015
walro added a commit that referenced this issue Oct 30, 2015
There were lots of options to go with there:

* nil check in #scheme or #normalized_scheme
* .to_s in #scheme or #normalized_scheme
* use Addressable’s #normalized_scheme

I don’t think nil checks are that pretty, so that one was quickly
discarded. I also don’t think we should #to_s “randomly” for some
properties it’s either all or nothing in my opinion. Using
Addressable’s own #normalized_scheme was the top candidate, but it did
additional things to the url (not just downcasing it) and I think it’s
a good thing that we try to control what we can when it comes to
normalization.

So ultimately I went with this, I changed so that we check against
#scheme instead of #normalized_scheme as that makes a whole lot of
sense to me at least.

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

Successfully merging a pull request may close this issue.

1 participant