From 73d8b58f6a2ed1c9f49684e867d2b42a8cd82920 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 17 Nov 2016 11:53:08 +0100 Subject: [PATCH] Improved trimming regex The old regex cause a segmentation fault when dealing with very large chunks of whitespace not at the end of the string. --- wcfsetup/install/files/lib/util/StringUtil.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/util/StringUtil.class.php b/wcfsetup/install/files/lib/util/StringUtil.class.php index cb468fe127..dbf98564c6 100644 --- a/wcfsetup/install/files/lib/util/StringUtil.class.php +++ b/wcfsetup/install/files/lib/util/StringUtil.class.php @@ -79,7 +79,7 @@ final class StringUtil { // Whitespace + (narrow) non breaking spaces. // No one can triforce now. $text = preg_replace('/^(\s|'.chr(226).chr(128).chr(175).'|'.chr(194).chr(160).')+/', '', $text); - $text = preg_replace('/(\s|'.chr(226).chr(128).chr(175).'|'.chr(194).chr(160).')+$/', '', $text); + $text = preg_replace('/([^\s'.chr(226).chr(194).']++)(?:\s|'.chr(226).chr(128).chr(175).'|'.chr(194).chr(160).')++$/', '\\1', $text); return $text; } -- 2.20.1