Skip to content

Commit

Permalink
fix: the query string is not appended to the end of the url if an act…
Browse files Browse the repository at this point in the history
…ion is specified
  • Loading branch information
grappendorf committed Sep 28, 2015
1 parent 70b6dd5 commit fa19188
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions grapp-rest-resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,15 @@
_prepareUrl: function(path, query, params, id, action) {
var name, url, value;
url = this.baseUrl ? this.baseUrl + path : path;
if (query) {
url += '?' + query;
}
if (typeof params === 'string') {
params = JSON.parse(params);
}
if (action) {
url += "/" + action;
}
if (query) {
url += '?' + query;
}
for (name in params) {
value = params[name];
url = url.replace(":" + name, value);
Expand All @@ -189,9 +192,6 @@
url = url.replace(/\/\/+/g, '/');
url = url.replace(/^(\w+):\//, '$1://');
url = url.replace(/\/$/, '');
if (action) {
url += "/" + action;
}
return url;
},
_prepareHeaders: function() {
Expand Down
6 changes: 3 additions & 3 deletions src/grapp-rest-resource.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ Polymer

_prepareUrl: (path, query, params, id, action) ->
url = if @baseUrl then @baseUrl + path else path
url += '?' + query if query
params = JSON.parse(params) if typeof(params) == 'string'
if action
url += "/#{action}"
url += '?' + query if query
for name, value of params
url = url.replace ":#{name}", value
url = url.replace ':id', id || ''
url = url.replace /\/\/+/g, '/'
url = url.replace /^(\w+):\//, '$1://'
url = url.replace /\/$/, ''
if action
url += "/#{action}"
url

_prepareHeaders: ->
Expand Down
2 changes: 1 addition & 1 deletion test/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
request.respond 200, {'Content-Type': 'application/json'}, '"request-with-special-index-query"'
@server.respondWith 'GET', '/data?type=show', (request) ->
request.respond 200, {'Content-Type': 'application/json'}, '"request-with-special-show-query"'
@server.respondWith 'GET', '/data?type=new', (request) ->
@server.respondWith 'GET', '/data/new?type=new', (request) ->
request.respond 200, {'Content-Type': 'application/json'}, '"request-with-special-new-query"'
@server.respondWith 'POST', '/data?type=create', (request) ->
request.respond 200, {'Content-Type': 'application/json'}, '"request-with-special-create-query"'
Expand Down

0 comments on commit fa19188

Please sign in to comment.