diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb
index ecb76c383..6305013a4 100644
--- a/lib/html_sanitizer.rb
+++ b/lib/html_sanitizer.rb
@@ -375,7 +375,7 @@ cleanup html string:
def self.cleanup_target(string, **options)
cleaned_string = CGI.unescape(string).utf8_encode(fallback: :read_as_sanitized_binary)
- cleaned_string = cleaned_string.delete(' ') unless options[:keep_spaces]
+ cleaned_string = cleaned_string.gsub(/[[:space:]]/, '') if !options[:keep_spaces]
cleaned_string = cleaned_string.strip
.delete("\t\n\r\u0000")
.gsub(%r{/\*.*?\*/}, '')