Skip to content

Commit

Permalink
Add ::Pair dispatch to escapeuri (#56)
Browse files Browse the repository at this point in the history
* Add `::Pair` dispatch to `escapeuri`

The docstring for `URIs.URI` claims that passing a single query argument
as a `Pair` is valid. However, since there is no method specifically for
pairs the fallback method is used. The fallback method assumes the
argument iterates key-value pairs, but since `Pair` iterates the two
components this will simply encode the first characters of the key-value
pair instead.

* Set version to 1.5.1.
  • Loading branch information
fredrikekre authored Oct 13, 2023
1 parent 4fd4515 commit dce395c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "URIs"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
authors = ["Jacob Quinn", "Sam O'Connor", "contributors: https://github.com/JuliaWeb/URIs.jl/graphs/contributors"]
version = "1.5.0"
version = "1.5.1"

[compat]
julia = "1.6"
Expand Down
4 changes: 3 additions & 1 deletion src/URIs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,10 @@ encoded within the query part of a URI.
"""
escapeuri(key, value) = string(escapeuri(key), "=", escapeuri(value))
escapeuri(key, values::Vector) = escapeuri(key => v for v in values)
escapeuri(query) = isempty(query) ? absent : join((escapeuri(k, v) for (k,v) in query), "&")
escapeuri(nt::NamedTuple) = escapeuri(pairs(nt))
escapeuri(p::Pair) = escapeuri((p,))
# Fallback method that expects the query argument to iterate key-value pairs
escapeuri(query) = isempty(query) ? absent : join((escapeuri(k, v) for (k,v) in query), "&")

decodeplus(q) = replace(q, '+' => ' ')

Expand Down
1 change: 1 addition & 0 deletions test/uri.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ urltests = URLTest[
@test URI(URI("http://google.com/user")) == URI("http://google.com/user")
@test URI(URI("http://google.com/user"); query=["key" => "value"]) == URI("http://google.com/user?key=value")
@test URI("http://google.com/user"; query=["key" => "value"]) == URI("http://google.com/user?key=value")
@test URI("http://google.com/user"; query="key" => "value") == URI("http://google.com/user?key=value")

# Precondition error messages refer to the function name (#32)
@test_throws ArgumentError("URI() requires `scheme in uses_authority || isempty(host)`") URI(; host="example.com")
Expand Down

2 comments on commit dce395c

@quinnj
Copy link
Member

@quinnj quinnj commented on dce395c Oct 13, 2023

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/93339

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.1 -m "<description of version>" dce395c350813226fbcb1394fd00ec0ae01f2f86
git push origin v1.5.1

Please sign in to comment.