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

replaced encodeURI with sdk.Url, issue #435 #437

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
9 changes: 7 additions & 2 deletions codegens/golang/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('./lodash'),
sdk = require('postman-collection'),
sanitize = require('./util').sanitize,
sanitizeMultiline = require('./util').sanitizeMultiline,
sanitizeOptions = require('./util').sanitizeOptions,
Expand Down Expand Up @@ -174,7 +175,7 @@ self = module.exports = {
}
options = sanitizeOptions(options, self.getOptions());

var codeSnippet, indent, trim, timeout, followRedirect,
var codeSnippet, indent, trim, timeout, followRedirect, finalUrl,
bodySnippet = '',
responseSnippet = '',
headerSnippet = '';
Expand Down Expand Up @@ -243,7 +244,11 @@ self = module.exports = {
}
codeSnippet += `${indent}"net/http"\n${indent}"io/ioutil"\n)\n\n`;

codeSnippet += `func main() {\n\n${indent}url := "${encodeURI(request.url.toString())}"\n`;
finalUrl = new sdk.Url(request.url.toString());
// URL encoding each part of Url individually
finalUrl = `${finalUrl.protocol}://${finalUrl.getRemote()}${finalUrl.getPathWithQuery(true)}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

A url may not have protocol present. For example if the url is postman.com/post, then finalURL.protocol will return undefined and the finalUrl will be undefined://postman.com/post which is invalid.

Infact I don't see why we need to manually construct the final URL. url.toString() does that for us.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, sorry. I was unfamiliar with url.toString(). I will make a necessary changes as soon as possible.


codeSnippet += `func main() {\n\n${indent}url := "${finalUrl}"\n`;
codeSnippet += `${indent}method := "${request.method}"\n\n`;

if (bodySnippet !== '') {
Expand Down
357 changes: 356 additions & 1 deletion codegens/golang/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading