Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/gooddata/helpers/global_helpers_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,23 @@ def decode_params(params, options = {})
end

begin
parsed_data_params = data_params.is_a?(Hash) ? data_params : JSON.parse(data_params)
parsed_data_params = if data_params.is_a?(Hash)
data_params
else
JSON.parse(sanitize_invalid_ascii_chars(data_params))
end
rescue JSON::ParserError => exception
reason = exception.message
reference_values.each { |secret_value| reason.gsub!("\"#{secret_value}\"", '"***"') }
raise exception.class, "Error reading json from '#{key}', reason: #{reason}"
end

begin
parsed_hidden_data_params = hidden_data_params.is_a?(Hash) ? hidden_data_params : JSON.parse(hidden_data_params)
parsed_hidden_data_params = if hidden_data_params.is_a?(Hash)
hidden_data_params
else
JSON.parse(sanitize_invalid_ascii_chars(hidden_data_params))
end
rescue JSON::ParserError => exception
raise exception.class, "Error reading json from '#{hidden_key}'"
end
Expand Down Expand Up @@ -240,6 +248,17 @@ def stringify_values(value)

private

# JSON does not allow unescaped ASCII control characters (0x00-0x1F) in strings.
# If such characters appear in the JSON payload coming from the platform, then we replace
# each raw control character with its escaped unicode form (\u0000 - \u001F).
def sanitize_invalid_ascii_chars(json_string)
return json_string unless json_string.is_a?(String)

json_string.gsub(/[\x00-\x1F]/) do |ch|
"\\u%04x" % ch.ord
end
end

def resolve_reference_params(data_params, params)
reference_values = []
regexps = Regexp.union(/\\\\/, /\\\$/, /\$\{([^\n\{\}]+)\}/)
Expand Down
Loading