Skip to content

Crash on response 'Link" header parsing  #68

@ivailop

Description

@ivailop

If a response 'Link' header not exactly formatted as:

Link: < uri-reference >; rel="value";

parsing it (as done at https://github.com/lostisland/sawyer/blob/master/lib/sawyer/response.rb#L52) results in a crash:

NoMethodError: undefined method `captures' for nil:NilClass
.../vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/response.rb:52:in `block in process_rels'
.../vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/response.rb:51:in `map'
.../vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/response.rb:51:in `process_rels'
.../vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/response.rb:20:in `initialize'
.../vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/agent.rb:107:in `new'
.../vendor/bundle/ruby/2.6.0/gems/sawyer-0.8.2/lib/sawyer/agent.rb:107:in `call'
.../vendor/bundle/ruby/2.6.0/gems/octokit-4.19.0/lib/octokit/connection.rb:156:in `request'
.../vendor/bundle/ruby/2.6.0/gems/octokit-4.19.0/lib/octokit/connection.rb:28:in `post'
.../vendor/bundle/ruby/2.6.0/gems/octokit-4.19.0/lib/octokit/client/users.rb:57:in `exchange_code_for_token'

By specification (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) the generic format is:

Link: < uri-reference >; param1=value1; param2="value2"

where:

  • the rel param is not required to be 1st
  • the value is not required to be quoted

In fact recent change in GitHub's API the returned header is like:

link: "<https://github.githubassets.com/assets/chunk-frameworks-aaac5e7e.js>; integrity=sha512-qqxefjEZzhP8x0ed+F3sDEdSogyDs+0ThK6EYXtqye9PJ26t5C996Q9EuRBr+296TAbc1rimsOSeZjZXJac1cA==; rel=preload; crossorigin=anonymous; as=script,<https://github.githubassets.com/assets/chunk-vendor-6594a208.js>; integrity=sha512-ZZSiCHJ85gkTIyggKfuBXsl3a7e+GPhw6iUguJ6eki2dXkGnOFBpQlUUG+gcTSJzgE8ii1cYyM7aLYXZeSeDbA==; rel=preload; crossorigin=anonymous; as=script,<https://github.githubassets.com/assets/behaviors-bf28db4d.js>; integrity=sha512-vyjbTdEGTiemoiT41KyVSh3+NxJv285wa1qlccyGrTsQsAAvhBSUrT0t1LZbJVEfccSTx+zLAyTekiljOX2wKA==; rel=preload; crossorigin=anonymous; as=script,<https://github.githubassets.com/assets/environment-f0adafbf.js>; integrity=sha512-8K2vvwbW+6H27Nad5ydg8PA2/aMD/LKq+EiK9s0U0hhVZxCI2tWBsYk9beAtisRw2j+Or5k2/F+6dk02nmj/PA==; rel=preload; crossorigin=anonymous; as=script"

Notice:

  • there is integrity before rel
  • rel is not quoted
  • there is no space after a , (comma)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions