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

Posting body as JSON escapes the content #177

Closed
jryd opened this issue Aug 15, 2018 · 5 comments
Closed

Posting body as JSON escapes the content #177

jryd opened this issue Aug 15, 2018 · 5 comments
Assignees

Comments

@jryd
Copy link

jryd commented Aug 15, 2018

I am using this library to post a collection of products to an API.

Some of the names of the products have special characters (e.g '&') and these are escaped using the below request:

_, err := client.R().SetHeader("Content-Type", "application/json").
	SetBody(product).
	Post("API URL")

Example:

Product name is Super Awesome & Fun

When posted with the above example request, it is sent as Super Awesome \u0026 Fun.

Looking at this StackOverflow answer: https://stackoverflow.com/a/39079238/1739852 it looks like it is possible to disable the HTML escaping on the encoder:

e.g

enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)

Would it be possible to add this as a configuration option to disable the escaping of HTML?

@jeevatkm
Copy link
Member

@jryd Sure, will add configuration to disable the escaping of HTML on JSON encoder/content-type.

@jeevatkm
Copy link
Member

@jryd I have added an option SetJSONEscapeHTML to disable HTML escape. Could you please give it a try on branch json-html-escape-opt and let me know? Then I will merge it master. Will be released in v1.9.0.

@jeevatkm jeevatkm self-assigned this Aug 25, 2018
@jeevatkm
Copy link
Member

jeevatkm commented Aug 25, 2018

Making v1.9.0 release.

@jryd
Copy link
Author

jryd commented Aug 29, 2018

@jeevatkm sorry for the late reply. Have tried using this in the v1.9.0 release and it looks like it is working well!

@jeevatkm
Copy link
Member

@jryd No worries, Thanks for the confirmation.

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

No branches or pull requests

2 participants