pjfanning opened a new pull request, #551: URL: https://github.com/apache/pekko-persistence-r2dbc/pull/551
### Motivation `MySQLJournalDao.tagsToJson` only escapes backslashes and double quotes, so a tag containing a control character such as a newline or tab produces invalid JSON for the `tags JSON` column. On MySQL the write fails with `R2dbcNonTransientResourceException: [3140] Invalid JSON text`, and the persistent actor stops. `tagsFromJson` also doesn't decode `\b`, `\f` or `\uXXXX`. MySQL normalizes stored JSON and returns those forms on read, so fixing only the encoder would make the write succeed but return corrupted tags. This matters more with #550, which enables the batched journal on these dialects. There, this error fails every request in the flush rather than just the entity that owns the tag. ### Modification - `tagsToJson` now escapes all characters below U+0020, using the short forms where JSON has them and `\u00XX` otherwise. - `tagsFromJson` now decodes `\b`, `\f` and `\uXXXX`, and throws `IllegalStateException` for a truncated or non-hexadecimal unicode escape. - Added unit tests to `MySQLTagsJsonSpec`, and a `PersistTagsSpec` integration test that round-trips these tags on every dialect. The existing row-reading code in that spec moved into a helper so both tests can use it. These helpers are shared, so the fix also covers snapshot and durable state tags and the query path. ### Result Tags containing control characters can be persisted on MySQL and read back unchanged on MySQL and MariaDB. Existing stored tags and the JSON produced for other tags don't change. ### Tests Before the fix: - `sbt -Dpekko.persistence.r2dbc.dialect=h2 "core/testOnly *MySQLTagsJsonSpec *PersistTagsSpec"`: 6 `MySQLTagsJsonSpec` tests failed - `sbt -Dpekko.persistence.r2dbc.dialect=mysql "core/testOnly *PersistTagsSpec"`: the new test failed with error 3140 After the fix, 31 of 31 passed with `core/testOnly *MySQLTagsJsonSpec *PersistTagsSpec` on: - MySQL 9.5.0 (Scala 2.13) - MariaDB 12.3.3 (Scala 2.13 and Scala 3) - H2 (Scala 2.13) Not verified locally, left to CI: - The last commit-ready edit changed the encoder's string literals to triple-quoted strings with the same values. It was not recompiled or rerun locally. - PostgreSQL and YugabyteDB: the local PostgreSQL run did not complete, so the new `PersistTagsSpec` test has not run on them. - MiMa: the local `core/mimaReportBinaryIssues` run was inconclusive. The only API change is a new private method on an `@InternalApi` object. ### References Refs #550 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
