lib/twitter-text/validation.rb in twitter-text-1.6.0 vs lib/twitter-text/validation.rb in twitter-text-1.6.1

- old
+ new

@@ -1,5 +1,7 @@ +require 'unf' + module Twitter module Validation extend self MAX_LENGTH = 140 DEFAULT_TCO_URL_LENGTHS = { @@ -21,11 +23,11 @@ # The string could also contain U+00E9 already, in which case the canonicalization will not change the value. # def tweet_length(text, options = {}) options = DEFAULT_TCO_URL_LENGTHS.merge(options) - length = ActiveSupport::Multibyte::Chars.new(text).normalize(:c).length + length = text.to_nfc.unpack("U*").length Twitter::Extractor.extract_urls_with_indices(text) do |url, start_position, end_position| length += start_position - end_position length += url.downcase =~ /^https:\/\// ? options[:short_url_length_https] : options[:short_url_length] end @@ -45,10 +47,10 @@ def tweet_invalid?(text) return :empty if !text || text.empty? begin return :too_long if tweet_length(text) > MAX_LENGTH return :invalid_characters if Twitter::Regex::INVALID_CHARACTERS.any?{|invalid_char| text.include?(invalid_char) } - rescue ArgumentError, ActiveSupport::Multibyte::EncodingError => e + rescue ArgumentError => e # non-Unicode value. return :invalid_characters end return false