asplake / link_header

In Ruby, parse and format HTTP link headers as described in the draft spec http://tools.ietf.org/id/draft-nottingham-http-link-header-06.txt
Other
36 stars 4 forks source link

Accept link attributes without quote such as rel=next #4

Closed miyagawa closed 10 years ago

miyagawa commented 10 years ago

The scanner was already setup to match the pattern, but there's an unnecessary gsub call in case of the match and caused runtime error such as:

> LinkHeader.parse('</path>; rel=next')
NoMethodError: undefined method `gsub' for nil:NilClass
       from {...}lib/ruby/gems/2.0.0/gems/link_header-0.0.7/lib/link_header.rb:94:in `parse'

This patch moves the gsub to only run in case of quoted match.

asplake commented 10 years ago

I'm all for avoiding a runtime error but can you give a stronger rationale for accepting unquoted attributes? They should be quoted, right?

miyagawa commented 10 years ago

No, it doesn't need to be, per I-D you quote in the readme and RFC 5988 as well: http://www.rfc-editor.org/rfc/rfc5988.txt

     link-extension    = token [ "=" ( token | quoted-string ) ]

Actually, the scanner regexp you already setup is coded to accept unquoted :) it just throws errors like described above, when that match happens.

  ATTR   = /#{TOKEN} *= *(#{TOKEN}|#{QUOTED}) */    #:nodoc:
asplake commented 10 years ago

Fair enough. I'll merge the request right away. I won't be able to publish a new gem for at least a few days though.

Out of curiousity, I'd love to know what you're using it for if you're able to share. You can email me at mjb@asplake.co.uk if you'd rather not do it here. Thanks!

miyagawa commented 10 years ago

I use it to ... parse Link headers in the API in tests, just like what it's designed for :)

asplake commented 10 years ago

:-)

Mike Burrows mjb@asplake.co.uk http://positiveincline.com http://positiveincline.com/index.php/about/ http://twitter.com/asplake +44 7785 236497

On 4 December 2013 14:40, Tatsuhiko Miyagawa notifications@github.comwrote:

I use it to ... parse Link headers in the API in tests, just like what it's designed for :)

— Reply to this email directly or view it on GitHubhttps://github.com/asplake/link_header/pull/4#issuecomment-29809537 .

asplake commented 10 years ago

Gem released also.