Rearrange article id parsing to be more reliable

The article ID parser looks for a string at the end of a URL path with
a bunch of hex digits. But it also has to handle user, tag, and search
URLs.

* /@ba5eba11
* /tag/0ddba11
* /search?q=ba5eba11

Some URLs are encoded as params. The parser used to look at the result
of the path first, then the params. But paths that ended in
`global-identity-2` messed that up because `2` is a hex digit at the
end of the path. This changes the logic to parse params first and paths
second which gets around this.
This commit is contained in:
Edward Loveall
2023-03-25 16:32:37 -04:00
parent cef1bc256d
commit e86108e18f
2 changed files with 9 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ class ArticleIdParser
def parse(request : HTTP::Request) : Maybe
from_params = post_id_from_params(request.query_params)
from_path = post_id_from_path(request.path)
from_path.or(from_params)
from_params.or(from_path)
end
private def post_id_from_path(request_path : String)