Skip to content

Commit

Permalink
fix: uri append (#594)
Browse files Browse the repository at this point in the history
* fix: uri append

* fix: uri append
  • Loading branch information
QizhengMo authored Dec 12, 2024
1 parent 9d6488f commit ce9fdcb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.arex.agent.bootstrap.util.CollectionUtil;
import io.arex.agent.bootstrap.util.StringUtil;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -20,22 +19,7 @@ private ServletUtil() {
}

public static String appendUri(String uri, String name, String value) {
try {
URI oldUri = URI.create(uri);
StringBuilder builder = new StringBuilder();
String newQuery = oldUri.getQuery();
if (oldUri.getQuery() == null) {
builder.append(name).append("=").append(value);
} else {
builder.append(newQuery).append("&").append(name).append("=").append(value);
}

URI newUri = new URI(oldUri.getScheme(), oldUri.getAuthority(),
oldUri.getPath(), builder.toString(), oldUri.getFragment());
return newUri.toString();
} catch (URISyntaxException e) {
return uri;
}
return UriComponentsBuilder.fromUriString(uri).queryParam(name, value).build().toString();
}

public static String getRequestPath(String uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ void appendUri() {

assertEquals("http://[email protected]&name=mark#fragment",
ServletUtil.appendUri("http://[email protected]#fragment", "name", "mark"));

assertEquals("http://arextest.com?Signature=HJeNHsZ7%2BDMj0JsTK3zd3nzBDQE%3D&name=mark",
ServletUtil.appendUri("http://arextest.com?Signature=HJeNHsZ7%2BDMj0JsTK3zd3nzBDQE%3D", "name", "mark"));
}

@Test
Expand Down

0 comments on commit ce9fdcb

Please sign in to comment.