diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-31 01:42:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-31 01:43:07 +0300 |
commit | ac9a8518364e91d64cb01732bf41896b6d2912b6 (patch) | |
tree | 066754ab194088efaa216ae87e841e0ee9f1e36f /config/initializers | |
parent | d455bcf1e412ab4a4abdfbe691fc40e3d4a0ce8a (diff) |
Add latest changes from gitlab-org/security/gitlab@13-10-stable-ee
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/json_validator_patch.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/config/initializers/json_validator_patch.rb b/config/initializers/json_validator_patch.rb new file mode 100644 index 00000000000..cb4158045ee --- /dev/null +++ b/config/initializers/json_validator_patch.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# This patches https://github.com/ruby-json-schema/json-schema/blob/765e6d8fdbfdaca1a42fa743f4621e757f9f6a03/lib/json-schema/validator.rb +# to address https://github.com/ruby-json-schema/json-schema/issues/148. +require 'json-schema' + +module JSON + class Validator + def initialize_data(data) + if @options[:parse_data] + if @options[:json] + data = self.class.parse(data) + elsif @options[:uri] + json_uri = Util::URI.normalized_uri(data) + data = self.class.parse(custom_open(json_uri)) + elsif data.is_a?(String) + begin + data = self.class.parse(data) + rescue JSON::Schema::JsonParseError + # Silently discard the error - use the data as-is + end + end + end + + JSON::Schema.stringify(data) + end + end +end |