Skip to content

fix: Node.URL.URLSearchParams keys & values return undefined #22

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

Merged
merged 6 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Breaking changes:
New features:

Bugfixes:
- `URLSearchParams.keys` and `.values` returned undefined due to a bug in the foreign code (#22 by @cakekindel)

Other improvements:
- Rename `uneffectfulHref` to `hrefPure` (used in `Show` instance) (#21 by @JordanMartinez)
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"purescript-tuples": "^7.0.0"
},
"devDependencies": {
"purescript-assert": "^6.0.0"
"purescript-assert": "^6.0.0",
"purescript-ordered-collections": "^3.1.1"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test -- --censor-lib --strict"
"test": "pulp test -- --censor-lib --strict",
"fmt": "purs-tidy format-in-place 'src/**/*.purs' 'test/**/*.purs'"
},
"devDependencies": {
"eslint": "^7.15.0",
"pulp": "16.0.0-0",
"purescript-psa": "^0.8.2",
"purs-tidy": "^0.10.0",
"rimraf": "^3.0.2"
}
}
4 changes: 2 additions & 2 deletions src/Node/URL/URLSearchParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const entriesImpl = (params, tuple) => {
return arr;
};
export const keysImpl = (params) => {
Array.from(params.keys());
return Array.from(params.keys());
};
export const valuesImpl = (params) => {
Array.from(params.values());
return Array.from(params.values());
};
50 changes: 46 additions & 4 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,53 @@ import Prelude

import Effect (Effect)
import Node.URL as URL
import Node.URL.URLSearchParams as URL.Search
import Foreign (unsafeReadTagged)
import Data.Bifunctor (lmap)
import Control.Monad.Except (runExcept)
import Control.Monad.Error.Class (liftEither)
import Effect.Exception (error)
import Data.Traversable (for)
import Data.Tuple (Tuple(..))
import Data.Map as Map
import Test.Assert (assertEqual)

main ∷ Effect Unit
main = do
let urlStr = "http://example.com/"
url <- URL.new urlStr
urlStr' <- URL.format url
assertEqual { expected: urlStr, actual: urlStr' }
-- Simple roundtrip
do
let urlStr = "http://example.com/"
url <- URL.new urlStr
urlStr' <- URL.format url
assertEqual { expected: urlStr, actual: urlStr' }

-- URLSearchParams
do
let urlStr = "http://example.com/?k&v=a&k&v=b"
url <- URL.new urlStr
search <- URL.searchParams url
keys <- URL.Search.keys search
valuesForeign <- URL.Search.values search

let
getStringOrThrow =
liftEither
<<< lmap (error <<< show)
<<< runExcept
<<< unsafeReadTagged "String"

values <- for valuesForeign getStringOrThrow

map <- Map.fromFoldable <$> for keys \k -> do
vs <- URL.Search.getAll k search
pure $ Tuple k vs

assertEqual { actual: keys, expected: [ "k", "v", "k", "v" ] }
assertEqual { actual: values, expected: [ "", "a", "", "b" ] }
assertEqual
{ actual: map
, expected: Map.fromFoldable
[ Tuple "k" [ "", "" ]
, Tuple "v" [ "a", "b" ]
]
}