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

fix: query params are not getting parsed from curl #3931

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions packages/bruno-app/src/components/Sidebar/NewRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
const Icon = forwardRef((props, ref) => {
return (
<div ref={ref} className="flex items-center justify-end auth-type-label select-none">
{curlRequestTypeDetected === 'http-request' ? "HTTP" : "GraphQL"}
{curlRequestTypeDetected === 'http-request' ? 'HTTP' : 'GraphQL'}
<IconCaretDown className="caret ml-1 mr-1" size={14} strokeWidth={2} />
</div>
);
Expand Down Expand Up @@ -139,7 +139,7 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
newHttpRequest({
requestName: values.requestName,
requestType: curlRequestTypeDetected,
requestUrl: request.url,
requestUrl: request.raw_url,
requestMethod: request.method,
collectionUid: collection.uid,
itemUid: item ? item.uid : null,
Expand All @@ -150,7 +150,7 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
)
.then(() => {
toast.success('New request created!');
onClose()
onClose();
})
.catch((err) => toast.error(err ? err.message : 'An error occurred while adding the request'));
} else {
Expand All @@ -166,7 +166,7 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
)
.then(() => {
toast.success('New request created!');
onClose()
onClose();
})
.catch((err) => toast.error(err ? err.message : 'An error occurred while adding the request'));
}
Expand Down Expand Up @@ -221,7 +221,7 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
return (
<StyledWrapper>
<Modal size="md" title="New Request" confirmText="Create" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<form className="bruno-form" onSubmit={(e) => e.preventDefault()}>
<div>
<label htmlFor="requestName" className="block font-semibold">
Type
Expand Down
6 changes: 5 additions & 1 deletion packages/bruno-app/src/utils/curl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export const getRequestFromCurlCommand = (curlCommand, requestType = 'http-reque
};

if (parsedBody && contentType && typeof contentType === 'string') {
if (requestType === 'graphql-request' && (contentType.includes('application/json') || contentType.includes('application/graphql'))) {
if (
requestType === 'graphql-request' &&
(contentType.includes('application/json') || contentType.includes('application/graphql'))
) {
body.mode = 'graphql';
body.graphql = parseGraphQL(parsedBody);
} else if (contentType.includes('application/json')) {
Expand All @@ -76,6 +79,7 @@ export const getRequestFromCurlCommand = (curlCommand, requestType = 'http-reque
}
return {
url: request.url,
raw_url: request.raw_url,
method: request.method,
body,
headers: headers,
Expand Down
19 changes: 17 additions & 2 deletions packages/bruno-app/src/utils/url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ export const parseQueryParams = (query) => {
return [];
}

return Array.from(new URLSearchParams(query.split('#')[0]).entries())
.map(([name, value]) => ({ name, value }));
return query
.split('#')[0]
.split('&')
.map((param) => {
const index = param.indexOf('=');

if (index === -1) {
// No '=' found, consider value as empty
return { name: param, value: '' };
}

const name = param.slice(0, index);
const value = param.slice(index + 1);

return { name, value };
})
.filter(({ name }) => hasLength(name));
} catch (error) {
console.error('Error parsing query params:', error);
return [];
Expand Down