diff --git a/packages/ui/src/parsers/curl.spec.ts b/packages/ui/src/parsers/curl.spec.ts index a03f2ca7..fa099aee 100644 --- a/packages/ui/src/parsers/curl.spec.ts +++ b/packages/ui/src/parsers/curl.spec.ts @@ -491,4 +491,21 @@ describe('curl', () => { expect(result1).toHaveProperty('0.url', 'https://httpbin.org/post/') expect(result2).toHaveProperty('0.url', 'https://httpbin.org/post') }) + + it('Body not imported #307', () => { + const cmd = `curl -X POST https://desec.io/api/v1/domains/{name}/rrsets/ \\ + --header "Authorization: Token {secret}" \\ + --header "Content-Type: application/json" --data \\ + '{"subname": "www", "type": "A", "ttl": 3600, "records": ["127.0.0.1", "127.0.0.2"]}' + ` + + console.log(cmd) + + const result = convert(cmd) + + expect(result).toHaveProperty( + '0.body.text', + `{"subname": "www", "type": "A", "ttl": 3600, "records": ["127.0.0.1", "127.0.0.2"]}` + ) + }) }) diff --git a/packages/ui/src/parsers/curl.ts b/packages/ui/src/parsers/curl.ts index 6d636c99..0b7c98c5 100644 --- a/packages/ui/src/parsers/curl.ts +++ b/packages/ui/src/parsers/curl.ts @@ -40,6 +40,20 @@ interface PairsByName { } const importCommand = (parseEntries: ParseEntry[]): ImportRequest => { + // fixes test case "Body not imported #307" { + let index = -1 + parseEntries = parseEntries.filter(entry => { + index++ + + const nextEntry = parseEntries[index + 1] + if(typeof nextEntry === 'string' && typeof entry === 'string' && entry.trim() === '' && nextEntry.trim().startsWith('-') == false) { + return false + } + + return true + }) + // } + // ~~~~~~~~~~~~~~~~~~~~~ // // Collect all the flags // // ~~~~~~~~~~~~~~~~~~~~~ //