parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
714 stars 133 forks source link

Use Jason Instead of JSX #179

Open jherdman opened 2 years ago

jherdman commented 2 years ago

Given that the broader Elixir community is circling their wagons around Jason, and issue #153, it seems that moving to Jason would be a wise choice.

NOTE: I'm having some challenges with the test suite that I hope to iron out. This should be considered draft. Help is more than welcome.

jherdman commented 2 years ago

One failure left:

  1) test hackney request with ssl options (ExVCR.RecorderHackneyTest)
     test/recorder_hackney_test.exs:157
     ** (Jason.EncodeError) invalid byte 0x82 in <<48, 130, 2, 11, 48, 130, 1, 145, 160, 3, 2, 1, 2, 2, 18, 17, 210, 187, 186, 51, 110, 212, 188, 230, 36, 104, 197, 13, 132, 29, 152, 232, 67, 48, 10, 6, 8, 42, 134, 72, 206, 61, 4, 3, 3, 48, 70, 49, 11, 48, ...>>
     code: use_cassette "record_hackney_with_ssl_options" do
     stacktrace:
       lib/jason.ex:199: Jason.encode_to_iodata!/2
       (exvcr 0.13.2) lib/exvcr/json.ex:14: ExVCR.JSON.save/2
       test/recorder_hackney_test.exs:158: ExVCR.RecorderHackneyTest."-test hackney request with ssl options/1-after$^0/0-0-"/1
       test/recorder_hackney_test.exs:158: (test)
jherdman commented 2 years ago

Failing test can be run via mix test --only wip

swissbeats93 commented 2 years ago

@jherdman I don't have time to test this at the moment but looking through the Jason documentation. More specifically, this part:

` The generation is controlled by the Jason.Encoder protocol, please refer to the module to read more on how to define the protocol for custom data types.

Options :escape - controls how strings are encoded. Possible values are:

:json (default) - the regular JSON escaping as defined by RFC 7159. :javascript_safe - additionally escapes the LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) characters to make the produced JSON valid JavaScript. :html_safe - similar to :javascript_safe, but also escapes the / character to prevent XSS. :unicode_safe - escapes all non-ascii characters. `

We need to specify a non-default escape option so that encode! does not raise an error. Edit: This reinforces the idea that it is an encoding problem

jherdman commented 2 years ago

@swissbeats93 thanks for the reply! Yeah, I tried those various options but with no luck. I'll give that forum post a better read ASAP.

jherdman commented 2 years ago

I haven't the time to get this over the hump. If anyone is interested in taking this over please feel free.