pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Wrong cyrilic encoding #1783

Open WhiteBite opened 7 months ago

WhiteBite commented 7 months ago

I have created a package in which DTO transfers from service 1 to service 2. Added application/json to the header. But it does not pass because when checking, it replaces Russian characters with other characters. what to do?

rholshausen commented 7 months ago

Try adding the correct charset to the content type header

WhiteBite commented 7 months ago

Try adding the correct charset to the content type header @rholshausen I don't want to add headers to the pact that aren't in real controllers. This is incorrect, add headers for tests. And I don't have any additional headers in production

WhiteBite commented 7 months ago

image image bad encoding...

WhiteBite commented 7 months ago

I think I found the mistake. In almost all examples, the header is either not specified or Content-type: application/json; charset=utf-8.

The problem is that spring considers Content-type: application/json; charset=utf-8 obsolete. And by default it writes the usual Content-type: application/json . And when I explicitly specify in tests that I expect Content-type: application/json, pact can't handle the encoding. I think this needs to be fixed.

I found some bad fixes. / 1) Add UTF-8 support to the Spring filter 2) Still write Content-type: application/json; charset=utf-8, despite the real answer. 3) Do not check headers

All options are bad and need to be discussed, I'm surprised no one has encountered this before

rholshausen commented 7 months ago

If there is no charset provided with the content type header, Pact-JVM will use the value returned by Charset.defaultCharset(). Please note that this may not always be UTF-8, but is dependent on the file.encoding system property. That could be UTF-16 or cp1252 on Windows.

WhiteBite commented 7 months ago

I am already checked this. All in UTF-8