Skip to content

JsonMapObjectReaderWriter not escaping the characters like \n properly#900

Closed
juniiorviani wants to merge 2 commits intoapache:mainfrom
juniiorviani:master
Closed

JsonMapObjectReaderWriter not escaping the characters like \n properly#900
juniiorviani wants to merge 2 commits intoapache:mainfrom
juniiorviani:master

Conversation

@juniiorviani
Copy link
Copy Markdown

Issue ref: https://issues.apache.org/jira/browse/CXF-8651

The JWS is generate with an invalid payload if I try to set a claim like this:

JwtClaims claims = new JwtClaims();

String claim = "GET\n\n\nWed, 19 Jan 2022 15:25:29 GMT\n/test/16c8a1ec-8d75-47a1-b138-46746713b8d8";
claims.setClaim("test", claim);

JwsCompactProducer jwsProducer = new JwsJwtCompactProducer(claims);

The JWS payload result will be: eyJ0ZXN0IjoiR0VUCgoKV2VkLCAxOSBKYW4gMjAyMiAxNToyNToyOSBHTVQKL3Rlc3QvMTZjOGExZWMtOGQ3NS00N2ExLWIxMzgtNDY3NDY3MTNiOGQ4In0

And when I decode the result is:
"{"test":"GET\n\n\nWed, 19 Jan 2022 15:25:29 GMT\n/test/16c8a1ec-8d75-47a1-b138-46746713b8d8"}"

This is an invalid payload because the json is stringify.. the json should be:

{ "test" : "GET\n\n\nWed, 19 Jan 2022 15:25:29 GMT\n/test/16c8a1ec-8d75-47a1-b138-46746713b8d8" }

- the strings is now properly escaped
@amarkevich
Copy link
Copy Markdown
Contributor

@juniiorviani could you add a unit test for this case?

@juniiorviani
Copy link
Copy Markdown
Author

juniiorviani commented Feb 7, 2022

Sure thing, @amarkevich I just added the unit tests

@coheigea
Copy link
Copy Markdown
Contributor

The tests are failing in this module, and checkstyle as well:

[ERROR] Failures:
[ERROR] JsonMapObjectReaderWriterTest.testAlreadyEscapedBackslash:210 expected:<a[]> but was:<a[]>
[ERROR] JsonMapObjectReaderWriterTest.testAlreadyEscapedDoubleQuotes:174

@gnodet
Copy link
Copy Markdown
Contributor

gnodet commented Mar 12, 2026

Closing — the underlying escaping bug was fixed in May 2024 (commit 204b0d3) by correcting the ESCAPED_CHARS set ('h' was replaced with 'n'). The test and checkstyle issues flagged by @coheigea were never addressed. Thank you @juniiorviani for the report.

@gnodet gnodet closed this Mar 12, 2026
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 this pull request may close these issues.

4 participants