Skip to content

Commit 07c96e4

Browse files
committedDec 18, 2014
Merge pull request #37 from johnmarkos/issue/37
replaceQueryParam() with three arguments adds newVal when oldVal missing
2 parents 9ac1bad + 19fd55c commit 07c96e4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎Uri.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@
284284
break;
285285
}
286286
}
287-
this.deleteQueryParam(key, decode(oldVal)).addQueryParam(key, newVal, index);
287+
if (index >= 0) {
288+
this.deleteQueryParam(key, decode(oldVal)).addQueryParam(key, newVal, index);
289+
}
288290
} else {
289291
for (i = 0; i < this.queryPairs.length; i++) {
290292
param = this.queryPairs[i];

‎test/uri/query.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('Uri', function() {
153153

154154
it('should be able to replace a param value with a specified value that does not exist', function() {
155155
q = new Uri('?page=4&page=2').replaceQueryParam('page', 3, 1)
156-
expect(q.toString()).to.equal('?page=4&page=2&page=3')
156+
expect(q.toString()).to.equal('?page=4&page=2')
157157
})
158158

159159
it('should replace a param value with an empty value if not provided a value', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.