Copy path View file

Large diffs are not rendered by default.

Oops, something went wrong.
Copy path View file

Large diffs are not rendered by default.

Oops, something went wrong.
Copy path View file
@@ -66,6 +66,9 @@
twttr.txt.regexen.rtl_chars = /[\u0600-\u06FF]|[\u0750-\u077F]|[\u0590-\u05FF]|[\uFE70-\uFEFF]/mg;
twttr.txt.regexen.non_bmp_code_pairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/mg;

// [\uFF00-\uFFEF] : Full-width roman + half-width katakana
twttr.txt.regexen.cjk_chars = /[\u2E80-\u2EFF]|[\u2F00-\u2FDF]|[\u2FF0-\u2FFF]|[\u3000-\u303F]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\u3100-\u312F]|[\u3130-\u318F]|[\u3190-\u319F]|[\u31A0-\u31BF]|[\u31C0-\u31EF]|[\u31F0-\u31FF]|[\u3200-\u32FF]|[\u3300-\u33FF]|[\u3400-\u4DBF]|[\u4DC0-\u4DFF]|[\u4E00-\u9FFF]|[\uFF00-\uFFEF]/mg;

twttr.txt.regexen.latinAccentChars = /\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u024F\u0253\u0254\u0256\u0257\u0259\u025B\u0263\u0268\u026F\u0272\u0289\u028B\u02BB\u0300-\u036F\u1E00-\u1EFF/;

// Generated from unicode_regex/unicode_regex_groups.scala, same as objective c's \p{L}\p{M}
@@ -993,7 +996,9 @@
};

twttr.txt.getUnicodeTextLength = function(text) {
return text.replace(twttr.txt.regexen.non_bmp_code_pairs, ' ').length;
return text
.replace(twttr.txt.regexen.cjk_chars, ' ')
.replace(twttr.txt.regexen.non_bmp_code_pairs, ' ').length;
};

twttr.txt.convertUnicodeIndices = function(text, entities, indicesInUTF16) {
@@ -1148,7 +1153,7 @@
return result;
};

var MAX_LENGTH = 140;
var MAX_LENGTH = 280;

// Returns the length of Tweet text with consideration to t.co URL replacement
// and chars outside the basic multilingual plane that use 2 UTF16 code points
Copy path View file
@@ -319,7 +319,7 @@

#pragma mark - Constants

static const NSInteger MaxTweetLength = 140;
static const NSInteger MaxTweetLength = 280;
static const NSInteger HTTPShortURLLength = 23;
static const NSInteger HTTPSShortURLLength = 23;

Copy path View file
@@ -18,7 +18,7 @@ @implementation TwitterTextTests

- (void)testRemainingCharacterCountForLongTweet
{
XCTAssertEqual([TwitterText remainingCharacterCount:@"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" httpURLLength:23 httpsURLLength:23], -10);
XCTAssertEqual([TwitterText remainingCharacterCount:@"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567891" httpURLLength:23 httpsURLLength:23], -10);
}

- (void)testHashtagBoundary
Copy path View file
@@ -7,22 +7,22 @@
"expected": true
},
{
"description": "Valid Tweet: 140 characters",
"description": "Valid Tweet: 280 characters",
"text": "A lie gets halfway around the world before the truth has a chance to get its pants on. Winston Churchill (1874-1965) http://bit.ly/dJpywL",
"expected": true
},
{
"description": "Valid Tweet: 140 characters (with accents)",
"description": "Valid Tweet: 280 characters (with accents)",
"text": "A lié géts halfway arøünd thé wørld béføré thé truth has a chance tø get its pants øn. Winston Churchill (1874-1965) http://bit.ly/dJpywL",
"expected": true
},
{
"description": "Valid Tweet: 140 characters (double byte characters)",
"description": "Valid Tweet: 280 characters (double byte characters)",
"text": "のののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののの",
"expected": true
},
{
"description": "Valid Tweet: 140 characters (double word characters)",
"description": "Valid Tweet: 280 characters (double word characters)",
"text": "🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱🐱",
"expected": true
},
@@ -32,13 +32,13 @@
"expected": false
},
{
"description": "Invalid Tweet: 141 characters",
"text": "A lie gets halfway around the world before the truth has a chance to get its pants on. -- Winston Churchill (1874-1965) http://bit.ly/dJpywL",
"description": "Invalid Tweet: 281 characters",
"text": "A lie gets halfway around the world before the truth has a chance to get its pants on. Winston Churchill (1874-1965) http://bit.ly/dJpywL A lie gets halfway around the world before the truth has a chance to get its pants on. Winston Churchill (1874-1965) http://bit.ly/dJpywL",
"expected": false
},
{
"description": "Invalid Tweet: 141 characters (due to newline)",
"text": "A lie gets halfway around the world before the truth has a chance to get its pants on. \n- Winston Churchill (1874-1965) http://bit.ly/dJpywL",
"description": "Invalid Tweet: 281 characters (due to newline)",
"text": "A lie gets halfway around the world before the truth has a chance to get its pants on.\nWinston Churchill (1874-1965) http://bit.ly/dJpywL A lie gets halfway around the world before the truth has a chance to get its pants on. Winston Churchill (1874-1965) http://bit.ly/dJpywL",
"expected": false
}
],
Copy path View file
@@ -2,7 +2,7 @@

module Twitter
module Validation extend self
MAX_LENGTH = 140
MAX_LENGTH = 280

DEFAULT_TCO_URL_LENGTHS = {
:short_url_length => 23,
Copy path View file
@@ -26,18 +26,18 @@ class TestValidation
TestValidation.new.tweet_invalid?("not-Unicode:\xfff0").should == :invalid_characters
end

it "should allow <= 140 combined accent characters" do
it "should allow <= 280 combined accent characters" do
char = [0x65, 0x0301].pack('U')
TestValidation.new.tweet_invalid?(char * 139).should == false
TestValidation.new.tweet_invalid?(char * 140).should == false
TestValidation.new.tweet_invalid?(char * 141).should == :too_long
TestValidation.new.tweet_invalid?(char * 280).should == false
TestValidation.new.tweet_invalid?(char * 281).should == :too_long
end

it "should allow <= 140 multi-byte characters" do
it "should allow <= 280 multi-byte characters" do
char = [ 0x1d106 ].pack('U')
TestValidation.new.tweet_invalid?(char * 139).should == false
TestValidation.new.tweet_invalid?(char * 140).should == false
TestValidation.new.tweet_invalid?(char * 141).should == :too_long
TestValidation.new.tweet_invalid?(char * 280).should == false
TestValidation.new.tweet_invalid?(char * 281).should == :too_long
end

end