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

Encode Spaces in URL #11

Merged
merged 2 commits into from
Mar 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function curlString(
options && options.headers && typeof options.headers === 'object';
const hasBody = options && options.body;

let curl = `curl --request ${method} \\\n--url ${url}${hasHeaders || hasBody ? ' \\' : ''
let curl = `curl --request ${method} \\\n--url ${url.replace(/\s/g, '%20')}${hasHeaders || hasBody ? ' \\' : ''
}`;

if (hasHeaders) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "curl-string",
"version": "3.0.0",
"version": "3.1.0",
"description": "Get human-readable cURL strings",
"scripts": {
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js && echo \"View Report here: $(pwd)/coverage/lcov-report/index.html\"",
Expand Down
5 changes: 5 additions & 0 deletions test/curlString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ test('To return a cURL for just a URL', () => {
--url http://example.com`);
});

test('To return a cURL with %20 for a URL with spaces', () => {
expect(curlString('http://example.com/?param=a nice blue sky')).toBe(`curl --request GET \\
--url http://example.com/?param=a%20nice%20blue%20sky`);
});

test('To handle lowercase `post` and a body', () => {
expect(
curlString(
Expand Down