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

Add test example of unquoted rel. #287

Merged
merged 7 commits into from
May 27, 2020

Conversation

jalcine
Copy link
Contributor

@jalcine jalcine commented Mar 27, 2019

This is the issue noticed in #286. It's also a real-world example held at https://webmention.rocks/

@jalcine
Copy link
Contributor Author

jalcine commented Mar 27, 2019

Already highlighted in first failure at https://travis-ci.org/teamon/tesla/jobs/512263620

@codecov
Copy link

codecov bot commented Mar 27, 2019

Codecov Report

Merging #287 into master will decrease coverage by 0.45%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #287      +/-   ##
==========================================
- Coverage    95.4%   94.94%   -0.46%     
==========================================
  Files          23       23              
  Lines         457      455       -2     
==========================================
- Hits          436      432       -4     
- Misses         21       23       +2
Impacted Files Coverage Δ
lib/tesla.ex 83.33% <0%> (-4.17%) ⬇️
lib/tesla/middleware/logger.ex 88.63% <0%> (-0.26%) ⬇️
lib/tesla/middleware/timeout.ex 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52d3a3b...390a267. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 27, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@3195e25). Click here to learn what that means.
The diff coverage is 75%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #287   +/-   ##
========================================
  Coverage          ?   95.2%           
========================================
  Files             ?      23           
  Lines             ?     459           
  Branches          ?       0           
========================================
  Hits              ?     437           
  Misses            ?      22           
  Partials          ?       0
Impacted Files Coverage Δ
lib/tesla/middleware/decode_rels.ex 88.88% <75%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3195e25...d08c0b5. Read the comment docs.

|> List.to_tuple()
case Regex.run(~r/\A<(.+)>; rel=(.+)\z/, item, capture: :all_but_first) do
nil ->
{}
Copy link
Member

Choose a reason for hiding this comment

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

iex(3)> [{}] |> Enum.into(%{})
** (ArgumentError) argument error
    (stdlib) :maps.from_list([{}])
    (elixir) lib/map.ex:174: Map.new/1

Empty tuple is not a good return value, this should be either ok/error tuple or a list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you suggest? Something like {:ok, []}?

Copy link
Member

Choose a reason for hiding this comment

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

It depends on what is valid and what not, in this case I think it should be an empty set of rels

link_rel ->
link_rel
|> Enum.reverse()
|> List.replace_at(0, String.trim(List.last(link_rel), "\""))
Copy link
Member

Choose a reason for hiding this comment

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

This one is quite hard to comprehend. Also, the first regex will match everything, it should probably have some stop point instead of .+

Copy link
Member

Choose a reason for hiding this comment

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

We should either parse key="something" or key=something, i.e. not accepting xxx="somthing (only one quote)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the first regex, you mean the \A<(.+)> bit? It doesn't seem to do that in the tests; especially since we discard the first matching result in the options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have suggestions on changes?

Copy link
Member

Choose a reason for hiding this comment

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

This bit rel=(.+) - it will match rel="hello while it should match only either rel=hello or rel="hello"

@teamon
Copy link
Member

teamon commented Apr 24, 2019

@jalcine 👋

@jalcine
Copy link
Contributor Author

jalcine commented Apr 24, 2019

Thanks for bumping this. I’ll be checking out your changes today!

(Originally published at: https://v2.jacky.wtf/post/ad63a126-378a-461e-991f-a4ad8b05edba)

@teamon
Copy link
Member

teamon commented May 31, 2019

Hey @jalcine, what's the status of this PR?

@teamon
Copy link
Member

teamon commented Jul 22, 2019

@jalcine 👋

@teamon
Copy link
Member

teamon commented Sep 5, 2019

@jalcine ping

@teamon teamon added the WIP label Sep 5, 2019
@teamon teamon mentioned this pull request Sep 5, 2019
@jalcine
Copy link
Contributor Author

jalcine commented Sep 13, 2019

@jalcine ping

Yo, my bad. I can take a look at this over the weekend - been busy with work. I've actually been working off my fork and I'd love to have this mainlined.

@jalcine
Copy link
Contributor Author

jalcine commented Oct 21, 2019

The errors in the runs are from TLS issues, unrelated to my changes. Should I rebase my branch or something?

@jalcine
Copy link
Contributor Author

jalcine commented Oct 25, 2019

hey @teamon; can you help me with this?

@teamon
Copy link
Member

teamon commented Nov 3, 2019

Yes, please start with rebase

@jalcine jalcine force-pushed the jalcine/check-regex-run-results branch from 707ee0f to 493f2f9 Compare November 4, 2019 02:57
@jalcine
Copy link
Contributor Author

jalcine commented Nov 4, 2019

Rebased and I'm getting the same TLS errors.

@teamon
Copy link
Member

teamon commented Nov 4, 2019

True, I'll take a look what's going on there and I'll merge this PR once fixed.

@teamon
Copy link
Member

teamon commented Nov 5, 2019

The ssl issue seems to be resolved on master now.

I'd merge this right away, but I've noticed there is one comment left - https://github.com/teamon/tesla/pull/287/files#r270899880.

@jalcine jalcine force-pushed the jalcine/check-regex-run-results branch 2 times, most recently from 86bd577 to e414c7f Compare November 20, 2019 21:23
@jalcine
Copy link
Contributor Author

jalcine commented Nov 22, 2019

I decided to forgo the regex and use string manipulation functions. I know this wasn't was prescribed originally but it works with the tests and follows the specification.

@jalcine jalcine requested a review from teamon November 22, 2019 22:01
Regex.run(~r/\A<(.+)>; rel="(.+)"\z/, item, capture: :all_but_first)
|> Enum.reverse()
|> List.to_tuple()
[url, param] = String.split(item, ";")
Copy link
Member

Choose a reason for hiding this comment

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

Won't this break with rel="some;thing" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add a test to check.

@teamon
Copy link
Member

teamon commented Apr 7, 2020

@jalcine Hey, what's the status of this PR?

@jalcine jalcine force-pushed the jalcine/check-regex-run-results branch from d08c0b5 to dcacf91 Compare May 15, 2020 07:38
@jalcine
Copy link
Contributor Author

jalcine commented May 15, 2020

Still working on this. Spent some time reading specs hoping I could close this ticket but it looks like it's expected of parser to understand the token form <https://URL> rel=token and quoted forms <https://URL> rel="token". It doesn't mention what kind of quote so I'll focus on the double quote form.

Spec reference: https://tools.ietf.org/html/rfc8288#section-3

@jalcine
Copy link
Contributor Author

jalcine commented May 15, 2020

https://regex101.com/r/tdUd2o/1 is what I've been using to test.

@jalcine
Copy link
Contributor Author

jalcine commented May 19, 2020

Bumping this @teamon

@jalcine jalcine requested a review from teamon May 20, 2020 08:32
@teamon teamon merged commit 593c717 into elixir-tesla:master May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants