Skip to content

Double quotes in body result in error (XML) #18

@Nathanjms

Description

@Nathanjms

I build up a request, and in the case that the body is XML string and has any attributes, eg. <?xml version="1.0" encoding="UTF-8"?>, the double quotes are not escaped.

This then means when I feed it through the library like the following:

CurlGenerator({
    method: request.method as 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
    url: request.url,
    body: request.body
}),

I receive an error, and can only fix it if I change the body to:

CurlGenerator({
    method: request.method as 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
    url: request.url,
    body: request.body.replace(/"/g, '\\"') // Escape all double quotes
}),

Is it worth considering adding the string escaping into the library directly, or is there a better way already here that I missed?

I imagine we could update

export function rawBodyToString(body: CurlRawBody): string {
  return body.content;
}

to

export function rawBodyToString(body: CurlRawBody): string {
  return body.content.replace(/"/g, '\\"')
}

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions