]> cat aescling's git repositories - mastodon.git/commitdiff
Fix length validator counting things that look like URIs like URLs (#4462)
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 31 Jul 2017 03:06:20 +0000 (05:06 +0200)
committerGitHub <noreply@github.com>
Mon, 31 Jul 2017 03:06:20 +0000 (05:06 +0200)
URI.extract is too strong, not limited to URLs, matched real text.
Same issue was present in language detector.

app/lib/language_detector.rb
app/validators/status_length_validator.rb

index 6d6ae2fb318db32142a39304f5564fb126f8f5e0..cc7509fdc8e9f9eace0644417c88d4389398182c 100644 (file)
@@ -33,9 +33,7 @@ class LanguageDetector
 
   def simplified_text
     text.dup.tap do |new_text|
-      URI.extract(new_text).each do |url|
-        new_text.gsub!(url, '')
-      end
+      new_text.gsub!(FetchLinkCardService::URL_PATTERN, '')
       new_text.gsub!(Account::MENTION_RE, '')
       new_text.gsub!(Tag::HASHTAG_RE, '')
       new_text.gsub!(/\s+/, ' ')
index abf250d6531463f451819e35dd9a2e126cb5ca6c..77be3f1f5437e79a253dc29726d4cd81ded5f19d 100644 (file)
@@ -24,7 +24,7 @@ class StatusLengthValidator < ActiveModel::Validator
 
   def countable_text(status)
     status.text.dup.tap do |new_text|
-      URI.extract(new_text).each { |url| new_text.gsub!(url, 'x' * 23) }
+      new_text.gsub!(FetchLinkCardService::URL_PATTERN, 'x' * 23)
       new_text.gsub!(Account::MENTION_RE, '@\2')
     end
   end