Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ sealed abstract case class Uri(scheme: String, authority: Authority, path: Path,
/**
* Returns a copy of this Uri with the given query.
*/
def withQuery(query: Query): Uri = copy(rawQueryString = if (query.isEmpty) None else Some(query.toString))
def withQuery(query: Query): Uri =
createUnsafe(scheme, authority, path, if (query.isEmpty) None else Some(query.toString), fragment)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider adding a copyUnsafe method and calling it here and also in all the other with... methods (this assumes that the query stored inside Uri is also already encoded).


/**
* Returns a copy of this Uri with the given query string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,12 @@ class UriSpec extends AnyWordSpec with Matchers {
uri.withRawQueryString("param1=val%22ue1") shouldEqual Uri("http://host/path?param1=val%22ue1#fragment")
uri.withRawQueryString("param1=val\"ue1") shouldEqual Uri("http://host/path?param1=val%22ue1#fragment")

uri.withQuery(Query("param1=val\"ue1")) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment")
uri.withQuery(Query(("param1", "val\"ue1"))) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment")
uri.withQuery(Query(Some("param1=val\"ue1"))) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment")
val query = Query.newBuilder.+=("param1" -> "val\"ue1").result()
uri.withQuery(query) shouldEqual Uri("http://host/path?param1=val%22ue1#fragment")

uri.withFragment("otherFragment") shouldEqual Uri("http://host/path?query#otherFragment")
}

Expand Down