UriBuilder 错误地编码查询参数值?

发布于 2024-09-01 03:36:40 字数 586 浏览 4 评论 0原文

让我们考虑以下代码示例,其中对路径和单个参数进行编码...

参数名称:“param”

参数值:“foo/bar?aaa=bbb&ccc=ddd”(恰好是带有查询参数的 url

   String test = UriBuilder.fromPath("https://dummy.com").
               queryParam("param", "foo/bar?aaa=bbb&ccc=ddd").
               build().toURL().toString();

)返回的编码 URL 字符串是:

 "https://dummy.com?param=foo/bar?aaa%3Dbbb&ccc%3Dddd"

这是正确的吗?

不应该是字符“&” (甚至可能是“?”)被编码在参数值字符串中?

生成的 URL 不会被解释如下:

第一个参数 name="param",value = "ar?aaa%3Dbbb" 后跟第二个参数 name="ccc%3Dddd",没有值。

Lets consider the following code sample where a path and single parameter are encoded...

Parameter name: "param"

Parameter value: "foo/bar?aaa=bbb&ccc=ddd" (happens to be a url with query parameters)

   String test = UriBuilder.fromPath("https://dummy.com").
               queryParam("param", "foo/bar?aaa=bbb&ccc=ddd").
               build().toURL().toString();

The encoded URL string returned is:

 "https://dummy.com?param=foo/bar?aaa%3Dbbb&ccc%3Dddd"

Is this correct ?

Should not the character "&" (and may be even "?") be encoded in the parameter value string ?

Would not the URL produced be interpreted as follow:

One first parameter, name="param", value = "ar?aaa%3Dbbb" followed by a second parameter, name="ccc%3Dddd", without value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿光 2024-09-08 03:36:40

您对“fromPath”的最初调用可能应该是“fromUri”。那是说...

这是正确的吗?

不,它看起来不像正确的输出。

不应该是字符“&” (并且可能
甚至是“?”)被编码在
参数值字符串?

是的,应该如此。

生成的 URL 不是
解释如下:

第一个参数,name="param",
value = "ar?aaa%3Dbbb" 后跟一个
第二个参数,name=“ccc%3Dddd”,
没有价值。

第一个参数是“foo/bar?aaa=bbb”,但是,是的,您解释得正确。这看起来像是 javax.ws.rs.core 提供程序中的错误。

Your initial call to "fromPath" should probably be "fromUri". That said...

Is this correct ?

No, it does not look like correct output.

Should not the character "&" (and may
be even "?") be encoded in the
parameter value string ?

Yes, it should be.

Would not the URL produced be
interpreted as follow:

One first parameter, name="param",
value = "ar?aaa%3Dbbb" followed by a
second parameter, name="ccc%3Dddd",
without value.

The first parameter would be "foo/bar?aaa=bbb", but yes, you're interpreting properly. This looks like a bug in your javax.ws.rs.core provider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文