Skip to content

Add String#undump - #445

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster17
Aug 25, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster17

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

String#undump was undefined (NoMethodError). It now parses a String#dump
literal back into the original string — the exact inverse of String#dump:

  • the named escapes \a \b \t \n \v \f \r \e, plus \" \\ \#;
  • \xHH (either hex case) to a byte;
  • \uXXXX and \u{XXXX …} (one or more space-separated code points) to UTF-8;
  • printable ASCII kept verbatim; an unrecognized escape keeps its backslash;
  • a trailing .force_encoding("NAME") suffix sets the result encoding.

The receiver must be an ASCII-compatible encoding (else
Encoding::CompatibilityError). A missing or excess wrapping quote, a malformed
\x/\u escape, an out-of-range code point, a raw NUL or non-ASCII byte, a
trailing backslash, or a malformed/unknown .force_encoding suffix each raises
RuntimeError with MRI's message.

This also fixes String#dump: a non-ASCII-compatible source now dumps to a
US-ASCII string (the escaped text is pure ASCII) rather than carrying the source
encoding, so dump.undump round-trips such a string — closing the one error
that remained in core/string/dump_spec.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep; core/string/undump_spec 0 → 24,
core/string/dump_spec 16 → 17.

🤖 Generated with Claude Code

String#undump was undefined (NoMethodError). It now parses a String#dump literal
back into the original string, the exact inverse of the escaping String#dump
produces:

  - the named escapes \a \b \t \n \v \f \r \e, plus \" \\ \#;
  - \xHH (either hex case) to a byte;
  - \uXXXX and \u{XXXX ...} (one or more space-separated code points) to UTF-8;
  - printable ASCII kept verbatim; an unrecognized escape keeps its backslash;
  - a trailing .force_encoding("NAME") suffix sets the result encoding.

The receiver must be an ASCII-compatible encoding (else
Encoding::CompatibilityError). A missing or excess wrapping quote, a malformed
\x or \u escape, an out-of-range code point, a raw NUL or non-ASCII byte, a
trailing backslash, or a malformed/unknown .force_encoding suffix each raises
RuntimeError with MRI's message.

This also fixes String#dump: a non-ASCII-compatible source now dumps to a
US-ASCII string (the escaped text is pure ASCII) rather than carrying the source
encoding, so String#dump.undump round-trips such a string — closing the one
error that remained in core/string/dump_spec.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/string/undump_spec 0 -> 24, core/string/dump_spec
16 -> 17.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 2491ecb into main Aug 25, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster17 branch August 25, 2026 08:51
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.

1 participant