Skip to content

Encode slashes in path parameters #1015

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
13 changes: 1 addition & 12 deletions dist/lib/swagger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,18 +1464,7 @@ Operation.prototype.encodeQueryParam = function(arg) {
* TODO revisit, might not want to leave '/'
**/
Operation.prototype.encodePathParam = function(pathParam) {
var encParts, part, parts, i, len;
pathParam = pathParam.toString();
if (pathParam.indexOf('/') === -1) {
return encodeURIComponent(pathParam);
} else {
parts = pathParam.split('/');
encParts = [];
for (i = 0, len = parts.length; i < len; i++) {
encParts.push(encodeURIComponent(parts[i]));
}
return encParts.join('/');
}
return encodeURIComponent(pathParam.toString());
};

var Model = function(name, definition) {
Expand Down
13 changes: 1 addition & 12 deletions lib/swagger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,18 +1464,7 @@ Operation.prototype.encodeQueryParam = function(arg) {
* TODO revisit, might not want to leave '/'
**/
Operation.prototype.encodePathParam = function(pathParam) {
var encParts, part, parts, i, len;
pathParam = pathParam.toString();
if (pathParam.indexOf('/') === -1) {
return encodeURIComponent(pathParam);
} else {
parts = pathParam.split('/');
encParts = [];
for (i = 0, len = parts.length; i < len; i++) {
encParts.push(encodeURIComponent(parts[i]));
}
return encParts.join('/');
}
return encodeURIComponent(pathParam.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done with a much simpler approach:

return pathParam.toString().split('/').map(encodeURIComponent).join('/')

Please update the code and and add test if possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is to encode slashes as well.

};

var Model = function(name, definition) {
Expand Down