-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
uri module doesn't properly handle escape sequences in JSON #7586
Comments
Any suggestions for a fix for this, apart from removing \n's from our JSON? |
This bug seems bad as it:
Seems like the right thing to do here is either to not try to decode the content and let the user do so as appropriate, or to at least look at the |
…nsible#7586 Regression potential: - `raw_content` is written to `dest` file instead of decoded `content` - `raw_content` doubles module reply
Hi! Thanks very much for your interest in Ansible. It sincerely means a lot to us. On September 26, 2014, due to enormous levels of contribution to the project Ansible decided to reorganize module repos, making it easier We split modules from the main project off into two repos, http://github.com/ansible/ansible-modules-core and http://github.com/ansible/ansible-modules-extras If you would still like this ticket attended to, and believe this problem or idea is still present in the latest version of Ansible (1.7.2) or the development branch, we will need your help in having it reopened in one of the two new repos, and instructions are provided below. We apologize that we are not able to make this transition happen seamlessly, though this is a one-time change and your help is greatly appreciated -- Both sets of modules will ship with Ansible, though they'll receive slightly different ticket handling. To locate where a module lives between 'core' and 'extras'
Additionally, should you need more help with this, you can ask questions on:
Thank you very much! |
This should have been fixed in ansible/ansible-modules-core#537 however there are some other issues with that code. I've just submitted ansible/ansible-modules-core#1331 to try to fix those issues. If anyone is still interested in this, please test that PR to be sure it doesn't cause a regression in this fix. |
…7586 Regression potential: - `raw_content` is written to `dest` file instead of decoded `content` - `raw_content` doubles module reply
Issue Type:
Bug Report
Ansible Version:
ansible 1.5.4
Environment:
Ubuntu 12.04
Summary:
uri module calls
content.decode('unicode_escape')
on response, which means escape sequences in JSON responses aren't handled properlySteps To Reproduce:
You can test this by running this ansible command line against a test URL I uploaded:
Expected Results:
Output should have a "json" key with the PythonVersion string decoded properly.
Actual Results:
Further comments
Note that the output does not include the "json" key due to the above bug.
I've been trying to use the "uri" module and hitting an HTTP endpoint which returns some JSON with header
Content-Type: application/json
. However, one of the strings in my JSON has a line feed (\n
control character) in it. This is correctly escaped, and is valid JSON. However, the "uri" module does the following on the response content (see here):This decodes the
\n
string to a literal line feed, and causes thejson.loads()
further down to fail with an exception like:There's a catch-all exception around the json.loads() that silently ignores this error without setting the
.json
key.So two things:
Why does the uri module do this extra (un)escaping, effectively breaking the content in this case?
This issue was hardish to debug as the
json.loads()
has a catch-all except around it. (Catch-all except clauses are bad practice for this reason.) I recommend changing it to a "except ValueError, error" and then callmodule.fail_json()
with a string representation of the error in the response.The text was updated successfully, but these errors were encountered: