Skip to content

Commit e644918

Browse files
committed
Only replace query segment
1 parent 8ebdcd8 commit e644918

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

datamodel/odata-client/src/main/java/com/sap/cloud/sdk/datamodel/odata/client/request/ODataRequestResultGeneric.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ private void assertResultTypeIsNotVoid( @Nonnull final Class<?> cls )
754754
}
755755

756756
@Nonnull
757-
private String removeDuplicateQueryParameters( @Nonnull String nextLink )
757+
private String removeDuplicateQueryParameters( @Nonnull final String nextLink )
758758
{
759759
if( !(httpClient instanceof UriQueryMerger) ) {
760760
return nextLink;
@@ -763,18 +763,20 @@ private String removeDuplicateQueryParameters( @Nonnull String nextLink )
763763
if( query == null ) {
764764
return nextLink;
765765
}
766-
boolean changed = false;
766+
final String[] segments = nextLink.split("\\?", 2);
767767
final String[] queryArguments = query.split("&");
768768
for( final String argument : queryArguments ) {
769-
if( nextLink.contains(argument) ) {
770-
changed = true;
771-
nextLink = nextLink.replace(argument, "");
769+
if( segments[1].contains(argument) ) {
770+
segments[1] = segments[1].replace(argument, "");
772771
}
773772
}
774-
if( changed ) {
775-
nextLink = nextLink.replaceAll("&&+", "&").replace("?&", "?").replaceAll("&$", "");
776-
log.debug("Altered reference to next link: {}", nextLink);
773+
if( nextLink.length() + 1 == segments[0].length() + segments[1].length() ) {
774+
return nextLink;
777775
}
778-
return nextLink;
776+
// after removal of arguments clean-up query: fix "?foo=bar&&&one=1", fix "?&one=1", fix "foo=bar&"
777+
segments[1] = segments[1].replaceAll("&&+", "&").replace("?&", "?").replaceAll("&$", "");
778+
final String updatedLink = segments[0] + "?" + segments[1];
779+
log.debug("Altered reference to next link: {}", nextLink);
780+
return updatedLink;
779781
}
780782
}

0 commit comments

Comments
 (0)