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

bugfix(#2431) Refactor URL construction in Postman collection processing #2445

Merged
merged 9 commits into from
Sep 23, 2024

Conversation

sanjai0py
Copy link
Member

@sanjai0py sanjai0py commented Jun 12, 2024

Description

Fixes #2431

The PR improves the handling of URL construction when processing Postman collections. Previously, the code was not handling the case where the request.url field was an object without a raw field. The new code now correctly constructs the URL from the components of the request.url object when necessary.

Fixes #3113

Now the request method is converted to uppercase during import.

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Comment on lines 57 to 72
const constructUrl = (url) => {
let urlStr = '';
if (typeof url === 'string') {
urlStr = url;
} else if (url.raw) {
urlStr = url.raw;
} else {
const { protocol, host, path, port, query } = url;
const hostStr = Array.isArray(host) ? host.join('.') : host;
const pathStr = Array.isArray(path) ? path.join('/') : path;
const portStr = port ? `:${port}` : '';
const queryStr = query && query.length > 0 ? `?${query.map((q) => `${q.key}=${q.value}`).join('&')}` : '';
urlStr = `${protocol}://${hostStr}${portStr}/${pathStr}${queryStr}`;
}
return urlStr;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Check this case please, this is losing hash section of url:

"item": [
		{
			"name": "Request",
			"request": {
				"method": "GET",
				"header": [],
				"url": {
					"raw": "https://localhost/param1/param2?param3&param4=b&param5=(size=small;color=red)#this-is-framgment",
					"protocol": "https",
					"host": [
						"localhost"
					],
					"path": [
						"param1",
						"param2"
					],
					"query": [
						{
							"key": "param3",
							"value": null
						},
						{
							"key": "param4",
							"value": "b"
						},
						{
							"key": "param5",
							"value": "(size=small;color=red)"
						}
					],
					"hash": "this-is-framgment"
				}
			},
			"response": []
		}
	]

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the review. I believe we should not include the hash values in the URL. As per Wikipedia,

"The fragment identifier functions differently to the rest of the URI: its processing is exclusively client-sided with no participation from the web server"
Wikipedia

…en there is a param with its key as undefined we discard it.
@helloanoop helloanoop merged commit eb33504 into usebruno:main Sep 23, 2024
2 checks passed
@sanjai0py sanjai0py deleted the bugfix/postman-import branch September 24, 2024 08:42
Its-treason pushed a commit to Its-treason/bruno that referenced this pull request Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing a postman collection for commercetools fails Postman import silently drops url values
5 participants