diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2019-07-24 16:01:20 -0400 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-06-05 11:49:56 +0900 |
commit | f641d78a6fcf0b96c50077503a763478d0599fe5 (patch) | |
tree | 0a67ca59d70a6b3c195e1c395c1c812c0c422e23 /ext | |
parent | 4085c51a5175aeff2aeb8b849214c2899a79eb19 (diff) | |
download | ruby-f641d78a6fcf0b96c50077503a763478d0599fe5.tar.gz |
[ruby/psych] Implement `freeze` option for Pysch.load
https://github.com/ruby/psych/commit/7dae24894d
Diffstat (limited to 'ext')
-rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 68452e5c3e..a922f90831 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -32,16 +32,18 @@ module Psych def accept target result = super - return result if @domain_types.empty? || !target.tag - key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:') - key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/ + unless @domain_types.empty? || !target.tag + key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:') + key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/ - if @domain_types.key? key - value, block = @domain_types[key] - return block.call value, result + if @domain_types.key? key + value, block = @domain_types[key] + result = block.call value, result + end end + result = deduplicate(result).freeze if @freeze result end @@ -341,7 +343,7 @@ module Psych key = accept(k) if @symbolize_names key = key.to_sym - else + elsif !@freeze key = deduplicate(key) end val = accept(v) @@ -378,6 +380,8 @@ module Psych if RUBY_VERSION < '2.7' def deduplicate key if key.is_a?(String) + # It is important to untaint the string, otherwise it won't + # be deduplicated into an fstring, but simply frozen. -(key.untaint) else key |