diff options
Diffstat (limited to 'lib/gitlab/middleware/handle_malformed_strings.rb')
-rw-r--r-- | lib/gitlab/middleware/handle_malformed_strings.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/gitlab/middleware/handle_malformed_strings.rb b/lib/gitlab/middleware/handle_malformed_strings.rb index 84f7e2e1b14..b966395ee32 100644 --- a/lib/gitlab/middleware/handle_malformed_strings.rb +++ b/lib/gitlab/middleware/handle_malformed_strings.rb @@ -93,7 +93,8 @@ module Gitlab # We try to encode the string from ASCII-8BIT to UTF8. If we failed to do # so for certain characters in the string, those chars are probably incomplete # multibyte characters. - string.encode(Encoding::UTF_8).match?(NULL_BYTE_REGEX) + string.dup.force_encoding(Encoding::UTF_8).match?(NULL_BYTE_REGEX) + rescue ArgumentError, Encoding::UndefinedConversionError # If we're here, we caught a malformed string. Return true true |