From edbb34b3ac6c48950c41ab00a518308f358861af Mon Sep 17 00:00:00 2001 From: Edward Date: Tue, 28 Apr 2015 15:52:10 +0400 Subject: [PATCH] Wrong URI on after adding existing parameters Fixed issue with wrong URI after adding existing parameter. Old result ?param1=val1¶m1=val2 --- src/main/java/org/lightcouch/URIBuilder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/lightcouch/URIBuilder.java b/src/main/java/org/lightcouch/URIBuilder.java index c52600a..5cbb1a4 100644 --- a/src/main/java/org/lightcouch/URIBuilder.java +++ b/src/main/java/org/lightcouch/URIBuilder.java @@ -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; } @@ -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);