summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-06-07 09:26:24 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2018-06-07 09:26:24 +0000
commitbc5fd64142f0d9640b68989e1327b8a6bb10c8c8 (patch)
tree06206b8a98999b589beb81cbac37ceaeaadf48af /lib
parenta9155ab05eb68fdf5d6967d268d8be8de7af6ab8 (diff)
parent854c9636ec6aabd8941b31f0f2aa4e89c9c072ce (diff)
downloadgitlab-ce-bc5fd64142f0d9640b68989e1327b8a6bb10c8c8.tar.gz
Merge branch '45505-lograge_formatter_encoding' into 'master'
Enforce UTF-8 encoding on user input in LogrageWithTimestamp formatter Closes #45505 See merge request gitlab-org/gitlab-ce!19244
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
index 1e1fdabca93..0014ce2689b 100644
--- a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
+++ b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
@@ -2,8 +2,12 @@ module Gitlab
module GrapeLogging
module Formatters
class LogrageWithTimestamp
+ include Gitlab::EncodingHelper
+
def call(severity, datetime, _, data)
time = data.delete :time
+ data[:params] = utf8_encode_values(data[:params]) if data.has_key?(:params)
+
attributes = {
time: datetime.utc.iso8601(3),
severity: severity,
@@ -13,6 +17,19 @@ module Gitlab
}.merge(data)
::Lograge.formatter.call(attributes) + "\n"
end
+
+ private
+
+ def utf8_encode_values(data)
+ case data
+ when Hash
+ data.merge(data) { |k, v| utf8_encode_values(v) }
+ when Array
+ data.map { |v| utf8_encode_values(v) }
+ when String
+ encode_utf8(data)
+ end
+ end
end
end
end