Skip to content

Commit

Permalink
Merge pull request #11 from zvakanaka/url-encode-spaces
Browse files Browse the repository at this point in the history
Encode Spaces in URL
  • Loading branch information
zvakanaka authored Mar 17, 2023
2 parents 89a048d + cb07543 commit 25fd2fb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
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

0 comments on commit 25fd2fb

Please sign in to comment.