Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nathanjms opened this issue Nov 15, 2024 · 1 comment
Open

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

Nathanjms opened this issue Nov 15, 2024 · 1 comment

Comments

@Nathanjms
Copy link

Nathanjms commented Nov 15, 2024

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

@Nathanjms Nathanjms changed the title Double quotes in body result in error Double quotes in body result in error (XML) Nov 15, 2024
@albertodeago
Copy link
Owner

Hello @Nathanjms
Will try to have a look at this, but I'm not sure when I'll be able to as my schedule lately is quite messy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants