300 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Opus 5 84a30ecc87 [ruby/psych] Reject a reentrant Psych::Parser#parse
The parser calls back into Ruby for every event, so a handler can call
#parse again on the same object. That reinitialised the parser and
re-pointed it at new input while the outer loop was still driving it,
which left the outer loop reading the inner document's freed buffer, or
resuming on a parser with no input at all and tripping libyaml's
read_handler assertion.

Psych::Exception is used so the caller can rescue it, and the in-use
flag is cleared with rb_ensure so a parser stays reusable afterwards.

https://github.com/ruby/psych/commit/5f2e37dc1c

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 01:05:51 +00:00
Hiroshi SHIBATAandClaude Opus 5 b996e6d3dc [ruby/psych] Propagate an exception raised in handler#event_location
Every case of the event switch overwrote the rb_protect state, so only
the second result was ever tested and the state from the event_location
call was dropped. The parse then returned normally with the exception
silently discarded.

https://github.com/ruby/psych/commit/186c3fa343

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 01:05:51 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 82ab14ecb0 [ruby/psych] Address Copilot review feedback on the libfyaml backend
Reject canonical output with NotImplementedError instead of silently
ignoring the request, and honor the implicit flag in start_sequence and
start_mapping so an implicit tag is not printed as a redundant verbose
tag. Relax the unquoted-boolean dump test to allow an optional document
end marker. Also correct the version docstrings and a stale comment
about how the parser collects diagnostics.

https://github.com/ruby/psych/commit/23f60daff1

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 02:40:16 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 a02377fee8 [ruby/psych] Add positive tests for the libfyaml backend
Cover what the libfyaml backend does distinctly, each placed with the
concern it belongs to: the Psych::BACKEND and Psych.libfyaml_version
checks in test_psych.rb, the YAML 1.2 "Norway problem" boolean case in
test_boolean.rb, and the "1.1 booleans are not quoted" emission case in
test_string.rb. The 1.2 assertions are skipped on the default libyaml
backend so the same suite passes under both.

https://github.com/ruby/psych/commit/35d0a437a2

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 02:40:16 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 71c888d1a7 [ruby/psych] Make the test suite backend-aware for the libfyaml backend
Add a libfyaml? helper and guard the tests that intentionally diverge on
the experimental YAML 1.2 backend: yes/no/on/off are strings rather than
booleans, flow collections and block scalars are formatted differently,
tags and marks are reported differently, and non-ASCII tags/aliases are
rejected. test_boolean asserts the 1.2 string result directly; the
formatting and mark cases are skipped. The default libyaml build is
unaffected (every guard keys off Psych::BACKEND).

https://github.com/ruby/psych/commit/67b6365f5a

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 02:40:15 +00:00
Hiroshi SHIBATA fe5d317d74 [ruby/psych] Test other whitespace separators in datetime-like strings
The TIME pattern accepts any whitespace run between date and time, so
cover vertical tab, carriage return, form feed, and mixed separators
in addition to the plain tab case.

https://github.com/ruby/psych/issues/691

https://github.com/ruby/psych/commit/f22366aea5
2026-06-12 03:56:20 +00:00
Vasil Nesterov 09383bfae7 [ruby/psych] Fix parsing of strings with tab-separated datetime
https://github.com/ruby/psych/commit/0ac39324a0
2026-06-12 03:56:20 +00:00
Hiroshi SHIBATAandClaude Fable 5 402049edb9 [ruby/psych] Strip the BOM from UTF-32 strings too
The C extension transcodes UTF-32 strings to UTF-8 with the BOM
preserved, so they were truncated the same way as UTF-8 input.

https://github.com/ruby/psych/commit/a141387024

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 02:53:39 +00:00
Hiroshi SHIBATAandClaude Fable 5 be5995286d [ruby/psych] Strip a leading byte order mark before parsing
libyaml only discounts the BOM when it detects the stream encoding by
itself. Psych passes the encoding explicitly whenever it is known, and
on that path libyaml counts the BOM as a first-line character, shifting
every token on the first line one column right and silently terminating
a block mapping at the second line.

https://github.com/ruby/psych/issues/331

https://github.com/ruby/psych/commit/924c15ed1f

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 02:53:39 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 422347ea26 [ruby/psych] Reject non-Array/String classes for their subclass tags
!ruby/array, !seq and !ruby/string carry the same exposure just fixed
for the hash tags: the loader allocated the named class and replaced its
contents without checking the class was actually an Array or String
subclass. Apply the same subclass check so a permitted unrelated class
can no longer be allocated and populated through these tags.

https://github.com/ruby/psych/commit/73f0131b13

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 00:04:14 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 527d56a5ac [ruby/psych] Reject non-Hash classes for hash-with-ivars tags
!ruby/hash-with-ivars, !ruby/hash and !map are only emitted for Hash
subclasses, but the loader allocated whatever class the tag named and
populated its ivars directly. That let a permitted non-Hash class be
instantiated with attacker-chosen ivars, bypassing its init_with
validation. Verify the resolved class is a Hash subclass before use.

https://github.com/ruby/psych/commit/b08a71012e

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 00:04:14 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 ea6ce35094 [ruby/psych] Route !ruby/encoding through the class loader
safe_load resolved !ruby/encoding directly via ::Encoding.find,
bypassing the permitted_classes check that !ruby/object:Encoding
already honors. Load it through the class loader so Encoding is only
deserialized when permitted.

https://github.com/ruby/psych/commit/f2e4b9d365

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 00:04:13 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 14bc2930e1 [ruby/psych] Round the io_reader clamp down to a character boundary
Clamping the over-read at exactly the requested size could split a
multibyte character, since the string an IO returns may carry a
non-binary encoding. Round the cut down to the last character boundary
at or before the size so the bytes handed to libyaml are always whole
characters.

https://github.com/ruby/psych/commit/6201ae17c1

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 02:10:54 +00:00
Hiroshi SHIBATAandClaude Opus 4.8 770ccaa6fb [ruby/psych] Clamp io_reader copy to libyaml's buffer size
io_reader trusted IO#read to honour its size argument and copied
RSTRING_LEN(string) bytes into libyaml's fixed-capacity buffer. An
IO-like object whose #read over-returns wrote past the buffer end, a
heap out-of-bounds write reachable from Psych.load/safe_load/parse.
Clamp the copied length to the requested size.

https://github.com/ruby/psych/commit/99ecd94560

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 02:10:54 +00:00
Nobuyoshi Nakada c27ae8d91a [ruby/psych] Remove excessive check of message
The order of "unexpected" and "missing" keyword argument errors at
`Data#initialize` had not been defined strictly.

[Bug #21844](https://bugs.ruby-lang.org/issues/21844)
ruby/ruby#15910

https://github.com/ruby/psych/commit/ba748d9b04
2026-01-20 14:15:41 +00:00
Benoit Daloze abefd3e8ff [ruby/psych] Check that Data members match exactly
* Fixes https://github.com/ruby/psych/issues/760

https://github.com/ruby/psych/commit/952008c898
2025-12-15 22:48:40 +00:00
Étienne Barrié 65dbd571c1 [ruby/psych] Use Node#to_ruby parse_symbols option
https://github.com/ruby/psych/commit/907fd4fa97
2025-12-05 17:14:30 +00:00
Caleb Stewart 0e7e6858e3 [ruby/psych] Add option to disable symbol parsing
https://github.com/ruby/psych/commit/4e9d08c285
2025-12-04 00:42:17 +00:00
Hiroshi SHIBATA 6b7e3395a4 [ruby/psych] Revert "Alias value or join to take in old Ruby"
This reverts commit https://github.com/ruby/psych/commit/1a4d383efe0b.

https://github.com/ruby/psych/commit/2f51c02280
2025-06-04 05:51:19 +00:00
Hiroshi SHIBATA a77ec9a22c [ruby/psych] Alias value or join to take in old Ruby
https://github.com/ruby/psych/commit/1a4d383efe
2025-06-03 07:56:39 +00:00
Koichi Sasada ef2bb61018 Ractor::Port
* Added `Ractor::Port`
  * `Ractor::Port#receive` (support multi-threads)
  * `Rcator::Port#close`
  * `Ractor::Port#closed?`
* Added some methods
  * `Ractor#join`
  * `Ractor#value`
  * `Ractor#monitor`
  * `Ractor#unmonitor`
* Removed some methods
  * `Ractor#take`
  * `Ractor.yield`
* Change the spec
  * `Racotr.select`

You can wait for multiple sequences of messages with `Ractor::Port`.

```ruby
ports = 3.times.map{ Ractor::Port.new }
ports.map.with_index do |port, ri|
  Ractor.new port,ri do |port, ri|
    3.times{|i| port << "r#{ri}-#{i}"}
  end
end

p ports.each{|port| pp 3.times.map{port.receive}}

```

In this example, we use 3 ports, and 3 Ractors send messages to them respectively.
We can receive a series of messages from each port.

You can use `Ractor#value` to get the last value of a Ractor's block:

```ruby
result = Ractor.new do
  heavy_task()
end.value
```

You can wait for the termination of a Ractor with `Ractor#join` like this:

```ruby
Ractor.new do
  some_task()
end.join
```

`#value` and `#join` are similar to `Thread#value` and `Thread#join`.

To implement `#join`, `Ractor#monitor` (and `Ractor#unmonitor`) is introduced.

This commit changes `Ractor.select()` method.
It now only accepts ports or Ractors, and returns when a port receives a message or a Ractor terminates.

We removes `Ractor.yield` and `Ractor#take` because:
* `Ractor::Port` supports most of similar use cases in a simpler manner.
* Removing them significantly simplifies the code.

We also change the internal thread scheduler code (thread_pthread.c):
* During barrier synchronization, we keep the `ractor_sched` lock to avoid deadlocks.
  This lock is released by `rb_ractor_sched_barrier_end()`
  which is called at the end of operations that require the barrier.
* fix potential deadlock issues by checking interrupts just before setting UBF.

https://bugs.ruby-lang.org/issues/21262
2025-05-31 04:01:33 +09:00
Earlopain 0c94ae048a [ruby/psych] Fix dumping StringIO (and potentially others) on Ruby <= 2.7
In Ruby < 3.0, the superclass of StringIO was actually already `Data`,
but it doesn't have the expected shape. So, on these earlier versions it errors:
> NoMethodError: undefined method `members' for #<StringIO:0x00005641dd5f2880>
>    vendor/bundle/ruby/2.6.0/gems/psych-5.2.5/lib/psych/visitors/yaml_tree.rb:170:in `visit_Data'

This test doesn't fail on 2.7, presumably because it can pull in a newer `stringio` version.

https://github.com/ruby/psych/commit/0f40f56268
2025-05-12 16:19:38 +00:00
OrenGitHub e2f5e233b5 [ruby/psych] exception tests
https://github.com/ruby/psych/commit/1e9b79f699
2025-05-09 17:53:18 +00:00
OrenGitHub 42328d4ef4 [ruby/psych] more special cases
https://github.com/ruby/psych/commit/b33bf8b060
2025-05-09 17:53:18 +00:00
OrenGitHub 451e1dcf31 [ruby/psych] duplicate more tests
https://github.com/ruby/psych/commit/a3be6429bf
2025-05-09 17:53:17 +00:00
OrenGitHub ae299cc9cd [ruby/psych] add first test for safe load stream
https://github.com/ruby/psych/commit/336553b412
2025-05-09 17:53:17 +00:00
Nobuyoshi Nakada 430789dec4 [ruby/psych] Ensure to remove the test constants
https://github.com/ruby/psych/commit/dd3685aa67
2025-05-02 06:27:11 +00:00
nick evans 136dc52663 Add support for Data objects with ivars
This sets the ivars _before_ calling initialize, which feels wrong.  But
Data doesn't give us any mechanism for setting the members other than 1)
initialize, or 2) drop down into the C API.  Since initialize freezes
the object, we need to set the ivars before that.  I think this is a
reasonable compromise—if users need better handling, they can implement
their own `encode_with` and `init_with`.  But it will lead to unhappy
surprises for some users.

Alternatively, we could use the C API, similarly to Marshal.  Psych _is_
already using the C API for path2class and build_exception.  This would
be the least surprising behavior for users, I think.
2025-05-01 17:52:14 +00:00
nick evans a397e4d4b0 [ruby/psych] Add support for ruby 3.2 Data objects
https://github.com/ruby/psych/commit/788b844c83
2025-05-01 17:52:13 +00:00
Martin Meyerhoff bd1d6e8cd7 [ruby/psych] Fix loading/parsing regular expressions
This fixes the issue where regular expression would come back slightly
different after going through a YAML load/dump cycle. Because we're used
to having to escape forward slashes in regular expression literals
(because the literal is delimited by slashes), but the deserializer
takes the literal output from `Regexp#inspect` and feeds it as a string
into `Regexp.new`, which expects a string, not a Regexp literal, cycling
did not properly work before this commit.

I've also changed the code to be a bit more readable, I hope this
doesn't affect performance.

https://github.com/ruby/psych/commit/f4dd8dadad
2025-05-01 17:50:13 +00:00
Jean Boussier f55138c9e7 [ruby/psych] Handle Ruby 3.5 new Set class
Since `Set` no longer is a regular object class holding a Hash
it needs to be specially handled.

https://github.com/ruby/psych/commit/c2d185d27c
2025-04-30 18:31:33 +00:00
Nobuyoshi Nakada 49d49d5985 [ruby/psych] Format Date in ISO-8601 explicitly
Fix https://github.com/ruby/psych/pull/644

https://github.com/ruby/psych/commit/b1ade765ba
2025-03-27 14:56:49 +00:00
Hiroshi SHIBATA 3185550623 Make Pstore tests as optional 2025-01-10 10:19:39 +09:00
Hiroshi SHIBATA a4528f60e5 Omit Psych_Unit_Tests if ostruct is not available 2025-01-08 17:12:19 +09:00
Thierry Deo 2bf5d26eb9 [ruby/psych] Eagerly require date.
https://github.com/ruby/psych/commit/b2aa0032c0
2024-11-20 16:59:55 +00:00
John Meade efc77d535b [ruby/psych] Ensure strings with only underscores are not processed as Integer
A string similar to "0x____" should be treated as a string.
Currently it is processed as an Integer.

This alters the regex specified by http://yaml.org/type/int.html
to ensure at least one numerical symbol is present in the string
before converting to Integer.

https://github.com/ruby/psych/commit/81479b203e
2024-09-11 17:19:18 +00:00
Peter Zhu d1474affa8 [ruby/psych] Convert tabs to spaces in test/psych/test_yaml.rb
https://github.com/ruby/psych/commit/64bfc308f8
2024-08-09 19:35:29 +00:00
Robert Schulze d3b07b9845 [ruby/psych] Add :stringify_names option to convert symbol keys to string for dumping
https://github.com/ruby/psych/commit/3d051d89aa
2024-01-18 17:32:34 +00:00
Colin Kelley 77593495f7 [ruby/psych] issue #443: drop special tests for y, Y, n, N since they covered in the more general test
https://github.com/ruby/psych/commit/6750b35402
2024-01-17 00:45:06 +00:00
Colin Kelley 8ae24e6b08 [ruby/psych] issue #443: quote Y and N when dumping
https://github.com/ruby/psych/commit/93c8fb443a
2024-01-17 00:45:06 +00:00
Hiroshi SHIBATA edadd5b796 [ruby/psych] Typofix by misspell
https://github.com/ruby/psych/commit/fc9ca15999
2023-12-25 21:12:49 +09:00
Alexander Momchilov b3598f95fa [ruby/psych] Use assert_same in tests where applicable
https://github.com/ruby/psych/commit/0dc25a9d6a
2023-12-19 11:07:46 +09:00
Charles Oliver Nutter 5c501bcbdb [ruby/psych] Add test for code_point_limit
Only supported on JRuby currently.

https://github.com/ruby/psych/commit/0c1754eefe
2023-10-02 11:47:35 +09:00
Hiroshi SHIBATA b368990ce6 [ruby/psych] Skip BigDecimal tests when it's missing to load
https://github.com/ruby/psych/commit/e1dbfae7a6
2023-07-18 02:55:47 +00:00
Nobuyoshi Nakada 10e6626426 [ruby/psych] Prefer assert_include for simple strings
https://github.com/ruby/psych/commit/33024ce2b0
2023-06-12 03:02:10 +00:00
Charles Oliver Nutter 29133794a3 [ruby/psych] Update for stricter 1.2 syntax
This allows these tests to pass on SnakeYAML Engine -- which is a
1.2-only YAML library -- while still passing on libyaml 1.1.

https://github.com/ruby/psych/commit/f44269fc9b
2023-01-31 13:14:05 +09:00
Jean Boussier 8fded5f5d1 [ruby/psych] Fix RestrictedYAMLTree allowing the Symbol class should allow all symbols
Ref: https://github.com/ruby/psych/pull/495

That's how it works for `safe_load`:
```ruby
>> YAML.safe_load(':foo', permitted_classes: [Symbol])
=> :foo
```

So `safe_dump` should mirror that.

https://github.com/ruby/psych/commit/592a75a656
2023-01-23 02:07:23 +00:00
Jean Boussier 3161fd4372 [ruby/psych] Get rid of anonymous eval calls
Things declared in anonymous eval are always annoying to locate.

https://github.com/ruby/psych/commit/38871ad4e5
2023-01-11 10:08:13 +00:00
Jeremy EvansandNobuyoshi Nakada 7e8fa06022 Always issue deprecation warning when calling Regexp.new with 3rd positional argument
Previously, only certain values of the 3rd argument triggered a
deprecation warning.

First step for fix for bug #18797.  Support for the 3rd argument
will be removed after the release of Ruby 3.2.

Fix minor fallout discovered by the tests.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2022-12-22 11:50:26 -08:00
Hiroshi SHIBATA d928ebacb2 Merge Psych-5.0.1 2022-12-09 16:36:22 +09:00