summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMartin Meyerhoff <mamhoff@gmail.com>2025-02-04 18:00:44 +0100
committergit <svn-admin@ruby-lang.org>2025-05-01 17:50:13 +0000
commitbd1d6e8cd725e84addfac8583634458a624929ae (patch)
tree1fd5bc9ac5d510a47e1fececdb3bba6d28c1060d /test
parent67b91e780798b80038dbfb39a06831918a75259f (diff)
[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
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_yaml.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/test/psych/test_yaml.rb b/test/psych/test_yaml.rb
index 897a7c8935..bb9b25f250 100644
--- a/test/psych/test_yaml.rb
+++ b/test/psych/test_yaml.rb
@@ -35,6 +35,10 @@ class Psych_Unit_Tests < Psych::TestCase
assert_cycle(Regexp.new("foo\nbar"))
end
+ def test_regexp_with_slash
+ assert_cycle(Regexp.new('/'))
+ end
+
# [ruby-core:34969]
def test_regexp_with_n
assert_cycle(Regexp.new('',Regexp::NOENCODING))