You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add depth and size limits to Console::Format::Safe
Fold maximum-size enforcement into Safe rather than a separate wrapper:
- Rename `limit` to `depth_limit` (with a deprecated `limit:` alias) to
clarify it maps to JSON's `max_nesting`.
- Add `size_limit` (default 16 KiB, `nil` disables). When the fast
serialization exceeds it, the record is rebuilt field-by-field, keeping as
many top-level fields as fit.
- Unify the failure and size diagnostics into a single `truncated` object
mapping each degraded field to why: `true` (dropped for size) or its error
(value recovered, could not serialize directly). Falls back to
`truncated: true` when detail does not fit.
- Serialize hash-like records via `to_hash`.
Removes the separate Console::Format::Truncated class.
# A safe format for converting objects to strings.
12
12
#
13
-
# Handles issues like circular references and encoding errors.
13
+
# Handles issues like circular references, encoding errors, excessive nesting depth, and excessive output size.
14
14
classSafe
15
+
# The JSON fragment used as the truncation marker when dropped fields cannot be named.
16
+
TRUNCATED="\"truncated\":true"
17
+
15
18
# Create a new safe format.
16
19
#
17
20
# @parameter format [JSON] The format to use for serialization.
18
-
# @parameter limit [Integer] The maximum depth to recurse into objects.
21
+
# @parameter depth_limit [Integer] The maximum depth to recurse into objects (the JSON `max_nesting`).
22
+
# @parameter size_limit [Integer | Nil] The maximum byte size of the serialized output, or `nil` to disable size limiting. Limits below {TRUNCATED} (the minimal marker) cannot be honoured.
19
23
# @parameter encoding [Encoding] The encoding to use for strings.
Copy file name to clipboardExpand all lines: releases.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,11 @@
1
1
# Releases
2
2
3
+
## Unreleased
4
+
5
+
- Add a `size_limit` to `Console::Format::Safe` (default 16KiB) which rebuilds oversized records field-by-field, keeping as many top-level fields as fit within the limit.
6
+
- Degraded fields are recorded in a `truncated` object that maps each field name to why it was truncated: `true` (dropped for size) or the error (the value could not be serialized directly and a safe representation was kept in its place).
7
+
- Rename `Console::Format::Safe`'s `limit:` to `depth_limit:` (with a deprecated `limit:` alias) to clarify that it maps to JSON's `max_nesting`.
8
+
3
9
## v1.35.0
4
10
5
11
- Fix handling of `Errno::ENODEV` errors when calculating the width of a terminal that was been re-opened to `File::NULL`.
0 commit comments