Skip to content

Commit

Permalink
fix(ui): curl import > body not imported #307
Browse files Browse the repository at this point in the history
  • Loading branch information
flawiddsouza committed Jan 30, 2025
1 parent d1acf90 commit e25cf54
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/ui/src/parsers/curl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,19 @@ 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"]}'
`

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"]}`
)
})
})
14 changes: 14 additions & 0 deletions packages/ui/src/parsers/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
// ~~~~~~~~~~~~~~~~~~~~~ //
Expand Down

0 comments on commit e25cf54

Please sign in to comment.