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

Conversation

ShauryaAg
Copy link

Replaced encodeURI function with sdk.Url(urlString) from postman-collection to parse the URL

@ShauryaAg ShauryaAg changed the title fixed issue #435 replaced encodeURI with sdk.Url, issue #435 Jan 2, 2021
@ShauryaAg
Copy link
Author

One of test in golang is failing because the generated code snippet includes url := "https://google.com/" instead of url := "https://google.com"

Can someone help me with this? @webholik

@ShauryaAg
Copy link
Author

Made a few changes in test files as mentioned in #438

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.

@ShauryaAg
Copy link
Author

@webholik I have made the necessary changes, however url.toString() method doesn't URL encode ' (single-quote) and " (double-quote) character.

@ShauryaAg ShauryaAg requested a review from webholik January 8, 2021 10:08
@ShauryaAg
Copy link
Author

@webholik the test fails as it doesn't URL encode ' and " character.

I think a better approach would be to parse URLs using postman-collection only but then put checks if protocol is empty (and any other conditions that I might have missed)

Something like
finalUrl = `${url.protocol ? `${url.protocol}://` : '' }${url.getRemote()}${finalUrl.getPathWithQuery(true)}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants