From 017175bfa4e7f8d824596dce9d943948dcdaeb07 Mon Sep 17 00:00:00 2001 From: Adam Quinton Date: Fri, 17 Mar 2023 13:57:08 -0600 Subject: [PATCH 1/2] encode spaces in url --- index.js | 2 +- test/curlString.test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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/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( From cb0754359115a5ede7392f3aaa19019b1636670e Mon Sep 17 00:00:00 2001 From: Adam Quinton Date: Fri, 17 Mar 2023 13:58:22 -0600 Subject: [PATCH 2/2] update package --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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\"",