-
Notifications
You must be signed in to change notification settings - Fork 346
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
Add test example of unquoted rel. #287
Conversation
Already highlighted in first failure at https://travis-ci.org/teamon/tesla/jobs/512263620 |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #287 +/- ##
========================================
Coverage ? 95.2%
========================================
Files ? 23
Lines ? 459
Branches ? 0
========================================
Hits ? 437
Misses ? 22
Partials ? 0
Continue to review full report at Codecov.
|
lib/tesla/middleware/decode_rels.ex
Outdated
|> List.to_tuple() | ||
case Regex.run(~r/\A<(.+)>; rel=(.+)\z/, item, capture: :all_but_first) do | ||
nil -> | ||
{} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, []}
?
There was a problem hiding this comment.
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
lib/tesla/middleware/decode_rels.ex
Outdated
link_rel -> | ||
link_rel | ||
|> Enum.reverse() | ||
|> List.replace_at(0, String.trim(List.last(link_rel), "\"")) |
There was a problem hiding this comment.
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 .+
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
@jalcine 👋 |
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) |
Hey @jalcine, what's the status of this PR? |
@jalcine 👋 |
@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. |
The errors in the runs are from TLS issues, unrelated to my changes. Should I rebase my branch or something? |
hey @teamon; can you help me with this? |
Yes, please start with rebase |
707ee0f
to
493f2f9
Compare
Rebased and I'm getting the same TLS errors. |
True, I'll take a look what's going on there and I'll merge this PR once fixed. |
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. |
86bd577
to
e414c7f
Compare
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. |
lib/tesla/middleware/decode_rels.ex
Outdated
Regex.run(~r/\A<(.+)>; rel="(.+)"\z/, item, capture: :all_but_first) | ||
|> Enum.reverse() | ||
|> List.to_tuple() | ||
[url, param] = String.split(item, ";") |
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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.
@jalcine Hey, what's the status of this PR? |
d08c0b5
to
dcacf91
Compare
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 Spec reference: https://tools.ietf.org/html/rfc8288#section-3 |
https://regex101.com/r/tdUd2o/1 is what I've been using to test. |
Bumping this @teamon |
This is the issue noticed in #286. It's also a real-world example held at https://webmention.rocks/