xgbtxy opened a new pull request, #12446:
URL: https://github.com/apache/arrow-rs/pull/12446
# Which issue does this PR close?
- None (found while auditing user-provided temporal format serialization in
`arrow-json`).
# Rationale for this change
`WriterBuilder` / `EncoderOptions` allow callers to configure custom
temporal format strings via `with_date_format`, `with_datetime_format`,
`with_time_format`, `with_timestamp_format`, and `with_timestamp_tz_format`.
However, `JsonArrayFormatter::encode` wrapped raw formatted output in
literal `"` bytes without JSON string escaping, relying on an assumption
predating custom format support. As a result, custom formats containing quotes,
backslashes, newlines, or control characters silently produced malformed JSON
(for example, `with_date_format("\"%Y-%m-%d\"".into())` wrote
`{"dt":""2022-01-08""}`).
# What changes are included in this PR?
- Update `JsonArrayFormatter` in `arrow-json/src/writer/encoder.rs` to
format into a reusable `String` buffer and serialize it via `encode_string` so
JSON-special characters are properly escaped while keeping `RawArrayFormatter`
(used for unquoted decimals) unchanged.
- Remove the obsolete comment noting that custom format escaping had not
been revisited.
# Are these changes tested?
Yes. Added `writer::tests::test_write_temporal_with_escaped_custom_formats`
in `arrow-json/src/writer/mod.rs`, covering custom date/time/timestamp formats
containing `"`, `\`, and `\n` alongside default RFC3339 output, verified with
`serde_json::from_slice` and the full `arrow-json` unit and doc test suites.
# Are there any significant user-facing changes?
None; valid RFC3339 temporal outputs remain byte-identical, and custom
temporal formats containing JSON-special characters now emit valid escaped JSON
strings instead of invalid JSON.
# AI usage disclosure
This PR was prepared with AI coding assistant support for locating the
escaping omission, drafting the fix and unit test, and running formatting,
lint, and test checks; all changes and test results were reviewed directly.
--
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]