Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update to account if applications use single quotes instead of double quotes#5

Closed
AlaricWhitney wants to merge 4 commits into
peterhellberg:masterfrom
AlaricWhitney:master
Closed

Update to account if applications use single quotes instead of double quotes#5
AlaricWhitney wants to merge 4 commits into
peterhellberg:masterfrom
AlaricWhitney:master

Conversation

@AlaricWhitney

Copy link
Copy Markdown

Update to account if applications use single quotes instead of double quotes.
Example:

resp := &http.Response{Header: http.Header{}}
resp.Header.Set("Link", `<https://example.com/?page=2>; rel='next'`)

In its current state if you have rel with single quotes, the application panics. I have updated the regex to match single quotes, and I have updated the application to avoid panics.

Update to account if applications use single quotes instead of double quotes.
Added anti fragility checks
@AlaricWhitney

Copy link
Copy Markdown
Author

@peterhellberg Here's a PR for your consideration to improve your app! Thanks!

fixed quote selection for multiple values in header
@dmitshur

dmitshur commented Jan 1, 2022

Copy link
Copy Markdown

Not panicking seems like a good change. I think it may fix issue #6.

Do you know if RFC 5988 permits the relation-type to be quoted with a single quote in addition to double quote?

@peterhellberg

peterhellberg commented Jan 3, 2022

Copy link
Copy Markdown
Owner

@dmitshur I do not think it would be considered to be quoted, but ' is a ptokenchar which is used for link-extension, so at least there ' seems to be allowed in the value (potentially "surrounding" it)

If my understanding of the EBNF is correct relation-types allows for the values to be quoted exactly with <"> = <US-ASCII double-quote mark (34)> or not at all (with the value starting with LOALPHA or URI)

(I fully agree that this library shouldn't panic)

@peterhellberg

Copy link
Copy Markdown
Owner

@AlaricWhitney I'm sorry that there has been no activity on this for a really long time. I have not been able to focus on open source work for quite some time.

With the release of v1.2.0 we can now parse <https://example.com/?page=2>; rel='next' without panic

The resulting link.Group value (when encoded into JSON) looks like this:

{"'next'":{"URI":"https://example.com/?page=2","Rel":"'next'","Extra":{}}}

(Note that ' are retained in the key and value)

Example: https://go.dev/play/p/E5tQVHbNTsS

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