Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-17 03:09:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-17 03:09:16 +0300
commit678e8181aaa08fc1b89e2a2721c842fb46ed730a (patch)
treedd7cc73e69d701cddfba08ad19c3c34c1ff2a264 /lib/gitlab/middleware
parentb9033ad4157010ccd8f37437de131ed70af90f45 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/middleware')
-rw-r--r--lib/gitlab/middleware/handle_malformed_strings.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/gitlab/middleware/handle_malformed_strings.rb b/lib/gitlab/middleware/handle_malformed_strings.rb
index bf71268046e..84f7e2e1b14 100644
--- a/lib/gitlab/middleware/handle_malformed_strings.rb
+++ b/lib/gitlab/middleware/handle_malformed_strings.rb
@@ -89,8 +89,12 @@ module Gitlab
def string_malformed?(string)
# We're using match rather than include, because that will raise an ArgumentError
# when the string contains invalid UTF8
- string.match?(NULL_BYTE_REGEX)
- rescue ArgumentError
+ #
+ # 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)
+ rescue ArgumentError, Encoding::UndefinedConversionError
# If we're here, we caught a malformed string. Return true
true
end