diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-12-15 23:37:22 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-12-15 23:37:22 +0800 |
commit | bcc09ca76098e8e12b0a42454920e1d4df6434c2 (patch) | |
tree | 9e3bd1c2aab78934aef6a469a84356d10bfac8c6 /lib/gitlab | |
parent | e682e2f888fd84deefc7b4b028d00a55bdd1c3a5 (diff) | |
download | gitlab-ce-bcc09ca76098e8e12b0a42454920e1d4df6434c2.tar.gz |
Just use YAML.safe_load and assume the format
should be correct since it's already passing the
validation anyway.
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8088#note_20076187
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/serialize/yaml_variables.rb | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/lib/gitlab/serialize/yaml_variables.rb b/lib/gitlab/serialize/yaml_variables.rb index 68ca50ed60e..db1e7641c74 100644 --- a/lib/gitlab/serialize/yaml_variables.rb +++ b/lib/gitlab/serialize/yaml_variables.rb @@ -10,36 +10,16 @@ module Gitlab def load(string) return unless string - object = YAML.load(string) + object = YAML.safe_load(string, [Symbol]) - # We don't need to verify the object once we're using SafeYAML - if YamlVariables.verify_object(object) - YamlVariables.convert_object(object) - else - [] - end + object.map(&YamlVariables.method(:convert_key_value_to_string)) end def dump(object) YAML.dump(object) end - def verify_object(object) - YamlVariables.verify_type(object, Array) && - object.all? { |obj| YamlVariables.verify_type(obj, Hash) } - end - - # We use three ways to check if the class is exactly the one we want, - # rather than some subclass or duck typing class. - def verify_type(object, klass) - object.kind_of?(klass) && - object.class == klass && - klass === object - end - - def convert_object(object) - object.map(&YamlVariables.method(:convert_key_value_to_string)) - end + private def convert_key_value_to_string(variable) variable[:key] = variable[:key].to_s |