File tree 4 files changed +41
-0
lines changed
4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ public function parseTweet($tweet)
61
61
return new ParseResults ();
62
62
}
63
63
64
+ $ tweet = StringUtils::normalizeLineFeed ($ tweet );
64
65
$ normalizedTweet = StringUtils::normalizeFromNFC ($ tweet );
65
66
$ normalizedTweetLength = StringUtils::strlen ($ normalizedTweet );
66
67
Original file line number Diff line number Diff line change @@ -178,4 +178,13 @@ public static function charCount($string, $encoding = 'UTF-8')
178
178
179
179
return $ count ;
180
180
}
181
+
182
+ /**
183
+ * @param string $string
184
+ * @return string
185
+ */
186
+ public static function normalizeLineFeed (string $ string ): string
187
+ {
188
+ return str_replace ("\r\n" , "\n" , $ string );
189
+ }
181
190
}
Original file line number Diff line number Diff line change @@ -243,4 +243,24 @@ public function testParseTweetWithEmojiNumberWithKeycapWithoutVariantSelector()
243
243
$ this ->assertSame (0 , $ result ->validRangeStart );
244
244
$ this ->assertSame (1 , $ result ->validRangeEnd );
245
245
}
246
+
247
+ /**
248
+ * test for parseTweet with Carriage Return characters
249
+ */
250
+ public function testParseTweetWithCarriageReturn (): void
251
+ {
252
+ // @codingStandardsIgnoreStart
253
+ $ text = "We're expanding the character limit! We want it to be easier and faster for everyone to express themselves. \r\n\r\nMore characters. More expression. More of what's happening. \r\nhttps://cards.twitter.com/cards/gsby/4ztbu " ;
254
+ // @codingStandardsIgnoreEnd
255
+ $ result = $ this ->parser ->parseTweet ($ text );
256
+
257
+ $ this ->assertInstanceOf ('\Twitter\Text\ParseResults ' , $ result );
258
+ $ this ->assertSame (192 , $ result ->weightedLength );
259
+ $ this ->assertSame (685 , $ result ->permillage );
260
+ $ this ->assertSame (true , $ result ->valid );
261
+ $ this ->assertSame (0 , $ result ->displayRangeStart );
262
+ $ this ->assertSame (210 , $ result ->displayRangeEnd );
263
+ $ this ->assertSame (0 , $ result ->validRangeStart );
264
+ $ this ->assertSame (210 , $ result ->validRangeEnd );
265
+ }
246
266
}
Original file line number Diff line number Diff line change @@ -39,4 +39,15 @@ public function testCharCountEmoji()
39
39
$ this ->assertSame (4 , StringUtils::charCount ('🧕🏾 ' ), 'U+1F9D5 U+1F3FE woman with headscarf with medium-dark skin tone has 4 code point ' );
40
40
$ this ->assertSame (14 , StringUtils::charCount ('🏴 ' ), 'flag (England) has 14 code point ' );
41
41
}
42
+
43
+ /**
44
+ * Test for strip carriage return characters
45
+ *
46
+ * @return void
47
+ */
48
+ public function testNormalizeLineFeed (): void
49
+ {
50
+ $ this ->assertSame ("foo \nbar \n" , StringUtils::normalizeLineFeed ("foo \r\nbar \r\n" ), "Strip CR and leave LF " );
51
+ $ this ->assertSame ("foo \rbar " , StringUtils::normalizeLineFeed ("foo \rbar " ), "Do not strip CR only " );
52
+ }
42
53
}
You can’t perform that action at this time.
0 commit comments