Skip to content

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

Open

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

Activity

  1. changed the title [-]Double quotes in body result in error[/-] [+]Double quotes in body result in error (XML)[/+] on Nov 15, 2024
  2. albertodeago commented on Nov 19, 2024

    @albertodeago
    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

  3. albertodeago commented on Mar 28, 2025

    @albertodeago
    Owner

    @Nathanjms can you check if this is fixed with v0.4.2

  4. yoeven commented on Apr 24, 2025

    @yoeven

    The error is still there in v0.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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