safe_yaml 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/safe_yaml.rb CHANGED
@@ -27,6 +27,26 @@ module SafeYAML
27
27
  def restore_defaults!
28
28
  OPTIONS.clear.merge!(DEFAULT_OPTIONS)
29
29
  end
30
+
31
+ def tag_safety_check!(tag)
32
+ return if tag.nil?
33
+ if OPTIONS[:raise_on_unknown_tag] && !OPTIONS[:whitelisted_tags].include?(tag) && !tag_is_explicitly_trusted?(tag)
34
+ raise "Unknown YAML tag '#{tag}'"
35
+ end
36
+ end
37
+
38
+ if YAML_ENGINE == "psych"
39
+ def tag_is_explicitly_trusted?(tag)
40
+ false
41
+ end
42
+
43
+ else
44
+ TRUSTED_TAGS = ["tag:yaml.org,2002:str"].freeze
45
+
46
+ def tag_is_explicitly_trusted?(tag)
47
+ TRUSTED_TAGS.include?(tag)
48
+ end
49
+ end
30
50
  end
31
51
 
32
52
  module YAML
@@ -60,9 +60,7 @@ module SafeYAML
60
60
 
61
61
  def get_and_check_node_tag(node)
62
62
  tag = self.get_node_tag(node)
63
- if !!tag && @raise_on_unknown_tag && !tag_is_whitelisted?(tag)
64
- raise "Unknown YAML tag '#{tag}'"
65
- end
63
+ SafeYAML.tag_safety_check!(tag)
66
64
  tag
67
65
  end
68
66
 
@@ -3,7 +3,7 @@ monkeypatch = <<-EORUBY
3
3
  def safe_transform
4
4
  if self.type_id
5
5
  return unsafe_transform if SafeYAML::OPTIONS[:whitelisted_tags].include?(self.type_id)
6
- raise "Unknown YAML tag '#{self.type_id}'" if SafeYAML::OPTIONS[:raise_on_unknown_tag]
6
+ SafeYAML.tag_safety_check!(self.type_id)
7
7
  end
8
8
 
9
9
  SafeYAML::SyckResolver.new.resolve_node(self)
@@ -1,3 +1,3 @@
1
1
  module SafeYAML
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: