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

Unable to parse response body with bad characters #294

Open
itskingori opened this issue Mar 24, 2020 · 3 comments · May be fixed by #295
Open

Unable to parse response body with bad characters #294

itskingori opened this issue Mar 24, 2020 · 3 comments · May be fixed by #295

Comments

@itskingori
Copy link

itskingori commented Mar 24, 2020

I'm experiencing a JSON::ParserError because of a bad character (in my case it's 0x1b):

Screenshot 2020-03-24 at 16 59 18

Here's the stack trace that showed me where the issue was:

Screenshot 2020-03-24 at 16 55 21

This is the JSON.parse we're hitting ...

when 200, 201, 302
if to_send == "body" && send_json
return JSON.parse(response.body)
elsif to_send == "body"
return response.body
elsif to_send == "code"
return response.code
elsif to_send == "raw"
return response
end

I've been able to replicate using this file (jenkins-log-with-bad-character.txt):

[1] pry(main)> file = File.open("/Users/Kingori/Desktop/jenkins-log-with-bad-character.txt")
=> #<File:/Users/Kingori/Desktop/jenkins-log-with-bad-character.txt>
[2] pry(main)> file_data = file.read
=> "{\"comment\":\"Some gems seem to be missing from your /srv/bundle/cache directory.\\n\eCould not find rake-12.3.3 in any of the sources\"}\n"
[3] pry(main)> JSON.parse(file_data)
JSON::ParserError: 783: unexpected token at '{"comment":"Some gems seem to be missing from your /srv/bundle/cache directory.\nould not find rake-12.3.3 in any of the sources"}
'
from /Users/Kingori/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/json-2.3.0/lib/json/common.rb:156:in `parse'
[4] pry(main)> file_data.encoding
=> #<Encoding:UTF-8>
@hadrianvalentine
Copy link

Parsing with Oj doesn't seem to give this error. Making the switch might be a convenient fix for this.

JSON

irb(main):004:0> JSON.parse("{\"comment\":\"Some gems seem to be missing from your /srv/bundle/cache directory.\\n\eCould not find rake-12.3.3 in any of the sources\"}\n")
Traceback (most recent call last):
        1: from (irb):4
JSON::ParserError (783: unexpected token at '{"comment":"Some gems seem to be missing from your /srv/bundle/cache directory.\nould not find rake-12.3.3 in any of the sources"})
'

Oj

[6] pry(main)> Oj.load("{\"comment\":\"Some gems seem to be missing from your /srv/bundle/cache directory.\\n\eCould not find rake-12.3.3 in any of the sources\"}\n").first
=> ["comment",
 "Some gems seem to be missing from your /srv/bundle/cache directory.\n\eCould not find rake-12.3.3 in any of the sources"]

@grosser
Copy link
Collaborator

grosser commented Mar 20, 2023

hmmm this seems to be a more general problem

JSON.parse("\"\n\"")

does not work either
... but also this seems to mean that the jenkins server is at fault and not the client, since the \e should have been escaped to \\e right ?

@grosser
Copy link
Collaborator

grosser commented Mar 20, 2023

so prefer to open an issue with jenkins + make sure jenkins is up to date and then see what they say about this issue
the \e afaik usually is from an escape sequence, so that smells like some cli printing gone wrong :/

... can you reliably reproduce this or is this randomly happening or at a random position in the reply ?

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

Successfully merging a pull request may close this issue.

3 participants