diff --git a/index.js b/index.js index 860e082..e429488 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/package-lock.json b/package-lock.json index e630ff6..31811c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "curl-string", - "version": "3.0.0", + "version": "3.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "curl-string", - "version": "3.0.0", + "version": "3.1.0", "license": "MIT", "dependencies": { "color-json": "^3.0.2" diff --git a/package.json b/package.json index d984be5..18d2b37 100644 --- a/package.json +++ b/package.json @@ -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\"", diff --git a/test/curlString.test.js b/test/curlString.test.js index ac77480..7950862 100644 --- a/test/curlString.test.js +++ b/test/curlString.test.js @@ -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(