Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong URI after adding existing parameters #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions src/main/java/org/lightcouch/URIBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,19 @@ public URIBuilder path(String path, boolean encode) {
}

public URIBuilder query(String name, Object value) {
if (name != null && value != null)
this.qParams.add(String.format("%s=%s", name, value));
String qPV = String.format("%s=%s", name, value);
if (name != null && value != null) {
for(int i = 0; i < this.qParams.size(); ++i) {
String[] tokens = this.qParams.get(i).split("=");
if(tokens != null && tokens.length > 0) {
if(tokens[0].compareTo(name) == 0) {
this.qParams.set(i, qPV);
return this;
}
}
}
this.qParams.add(qPV);
}
return this;
}

Expand Down Expand Up @@ -133,6 +144,7 @@ private URI createUriEncoded() {
}

private void prepareQuery() {
query.delete(0, query.length());
for (int i = 0; i < qParams.size(); i++) {
String amp = (i != qParams.size() - 1) ? "&" : "";
query.append(qParams.get(i) + amp);
Expand Down