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

Percent encode query #214

Closed
wants to merge 3 commits into from
Closed

Conversation

@turboMaCk
Copy link
Member

@turboMaCk turboMaCk commented Oct 27, 2020

resolves #200

This PR has 2 commits:

  1. Fixes the issue itself
  2. Unification of createUrl function in search with routeToString to ensure compatibility of urls

Showcase

nix-search

elm.json Outdated Show resolved Hide resolved
{-| Fixes issue with elm/url not properly escaping string
-}
queryString : String -> Query.Parser (Maybe String)
queryString =
Query.map (Maybe.andThen Url.percentDecode) << Query.string


Copy link
Member Author

@turboMaCk turboMaCk Oct 27, 2020

Since Domen's PRs are still not merged we need to define fixed version ourselves.

Copy link
Collaborator

@garbas garbas Oct 27, 2020

💯

[ Url.Parser.map Home Url.Parser.top
, Url.Parser.map NotFound (Url.Parser.s "not-found")
, Url.Parser.map Packages
Copy link
Member Author

@turboMaCk turboMaCk Oct 27, 2020

I took a liberty and reformatted these parts a bit. This is all elm-format compatible.

{-| Fixes issue with elm/url not properly escaping string
-}
builderString : String -> String -> QueryParameter
builderString name =
Builder.string name << Url.percentEncode
Copy link
Member Author

@turboMaCk turboMaCk Oct 27, 2020

Since Domen's PRs are still not merged we need to define fixed version ourselves.

Copy link
Collaborator

@garbas garbas Oct 27, 2020

💯

src/Route.elm Outdated
in
"/" ++ String.join "/" path ++ "?" ++ String.join "&" (List.filterMap Basics.identity query)
routeToString =
uncurry Builder.absolute << routeToPieces
Copy link
Member Author

@turboMaCk turboMaCk Oct 27, 2020

this is the only use of uncurry from basics-extra

createUrl toRoute channel query show from size sort =
toRoute (Just channel) query show (Just from) (Just size) (Just <| toSortId sort)
|> Route.routeToString
Copy link
Member Author

@turboMaCk turboMaCk Oct 27, 2020

unification of URL building logic so we can keep fixes in single place.

Copy link
Collaborator

@garbas garbas Oct 27, 2020

🥇

@@ -320,6 +313,7 @@ type Channel
| Release_20_03
| Release_20_09


Copy link
Member Author

@turboMaCk turboMaCk Oct 27, 2020

elm format.

@@ -102,7 +103,7 @@ update navKey msg model =
let
( newModel, newCmd ) =
Search.update
"options"
Route.Options
Copy link
Collaborator

@garbas garbas Oct 27, 2020

❤️

@turboMaCk turboMaCk force-pushed the percent-encode-query branch from a0398fe to 171acbe Oct 27, 2020
Copy link
Collaborator

@garbas garbas left a comment

I've added the feedback. I'm closing the PR since @turboMaCk will push the branch to repo itself so we get nice previews.

import Url.Parser exposing ((<?>))
import Url.Parser.Query
import Url.Parser.Query as Query
Copy link
Collaborator

@garbas garbas Oct 27, 2020

I like to avoid using aliases and prefer to use absolute names.

I know it makes this bigger, but I find it much nicer when reading the code. Especially after some time, since I don't have to look at the header where the function is coming from.

If you don't have strong feelings about this I would like to revert this.

{-| Fixes issue with elm/url not properly escaping string
-}
builderString : String -> String -> QueryParameter
builderString name =
Builder.string name << Url.percentEncode
Copy link
Collaborator

@garbas garbas Oct 27, 2020

💯

createUrl toRoute channel query show from size sort =
toRoute (Just channel) query show (Just from) (Just size) (Just <| toSortId sort)
|> Route.routeToString
Copy link
Collaborator

@garbas garbas Oct 27, 2020

🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants