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

Value inserted into JSON via ERB doesn't match request if it has an escaped unicode symbol #1009

Open
maxim opened this issue Jan 10, 2024 · 1 comment

Comments

@maxim
Copy link

maxim commented Jan 10, 2024

(Started as a bug report, but realized it might be more of a feature request).

In Rails context, if you have

  • a cassette with a json request like {"key": "<%= var %>"}
  • you pass it { erb: { var: '>' } }
  • your code uses Rails' to_json to create the request body

then VCR will show you that it's trying to find body with {"key": "\u003e"}, and therefore cannot find a matching request. That's because Rails' to_json automatically escapes html-unsafe symbols, which should be okay in most situations. However, VCR will not recognize that it's technically the same json.

This can currently be remedied by using match_requests_on: [:body_as_json].

However, what do you think about VCR automatically using :body_as_json based on request and response content type?

Having to reconfigure matching by hand each time json is involved seems a bit tedious and error prone. The problem is, most json requests work without using :body_as_json, making it unclear why it exists, but then when you run into something like this, you spend quite a while debugging, and then go "ahhh, now it makes sense". What are your thoughts? Potential downsides?

@galori
Copy link
Collaborator

galori commented Dec 16, 2024

Just curious about your specific case - would configuring this globally in your app work?

VCR.configure do |c|
  c.default_cassette_options = { match_requests_on: [:body_as_json] }
end

(or does this cause non-json bodies to break?)

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

No branches or pull requests

2 participants