webmock icon indicating copy to clipboard operation
webmock copied to clipboard

WebMock::Util::JSON parsing issue (Psych::SyntaxError)

Open costa opened this issue 10 years ago • 4 comments

I've been mocking some Pusher API requests and I'm getting the following error when trying to match against a hash: Psych::SyntaxError: (<unknown>): found unknown escape character while parsing a quoted scalar at line 1 column 62

Upon breaking on lib/webmock/util/json.rb:12, here's what I've found:

(byebug) ::JSON.parse json
{"name"=>"created", "channels"=>["user-session-35"], "data"=>"{\"id\":40,\"user_name\":\"Janice Henry\",\"user_pic_url\":\"http://graph.facebook.com/LryFxIBnL0c/picture?width=100\\u0026height=100\",\"is_destroyed\":false}"}
(byebug) ::JSON.parse ::JSON.parse(json)["data"]
{"id"=>40, "user_name"=>"Janice Henry", "user_pic_url"=>"http://graph.facebook.com/LryFxIBnL0c/picture?width=100&height=100", "is_destroyed"=>false}
(byebug) JSON.parse json
Psych::SyntaxError Exception: (<unknown>): found unknown escape character while parsing a quoted scalar at line 1 column 62
nil

It turns out it fails to parse "\u0026", I'm not sure why you would need a different JSON parsing method, but it looks like a pretty annoying bug.

costa avatar Nov 06 '14 17:11 costa