From 61f24ccd90d2b7c48b2d5091c11964f455e8e9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be> Date: Thu, 10 Feb 2011 19:49:21 +0100 Subject: Fixed linkification of URLs followed by newlines. Resolves: #762 diff --git a/SwifTools/Linkify.cpp b/SwifTools/Linkify.cpp index 32428ec..822536e 100644 --- a/SwifTools/Linkify.cpp +++ b/SwifTools/Linkify.cpp @@ -21,7 +21,7 @@ String Linkify::linkify(const String& input) { for (size_t i = 0; i < input.getUTF8Size(); ++i) { char c = input[i]; if (inURL) { - if (c != ' ' && c != '\t') { + if (c != ' ' && c != '\t' && c != '\n') { currentURL.push_back(c); } else { diff --git a/SwifTools/UnitTest/LinkifyTest.cpp b/SwifTools/UnitTest/LinkifyTest.cpp index 60edc9b..a35a686 100644 --- a/SwifTools/UnitTest/LinkifyTest.cpp +++ b/SwifTools/UnitTest/LinkifyTest.cpp @@ -29,6 +29,8 @@ class LinkifyTest : public CppUnit::TestFixture { CPPUNIT_TEST(testLinkify_At); CPPUNIT_TEST(testLinkify_Amps); CPPUNIT_TEST(testLinkify_UnicodeCharacter); + CPPUNIT_TEST(testLinkify_NewLine); + CPPUNIT_TEST(testLinkify_Tab); CPPUNIT_TEST_SUITE_END(); public: @@ -160,6 +162,22 @@ class LinkifyTest : public CppUnit::TestFixture { String("<a href=\"http://\xe2\x98\x83.net\">http://\xe2\x98\x83.net</a>"), result); } + + void testLinkify_NewLine() { + String result = Linkify::linkify("http://swift.im\nfoo"); + + CPPUNIT_ASSERT_EQUAL( + String("<a href=\"http://swift.im\">http://swift.im</a>\nfoo"), + result); + } + + void testLinkify_Tab() { + String result = Linkify::linkify("http://swift.im\tfoo"); + + CPPUNIT_ASSERT_EQUAL( + String("<a href=\"http://swift.im\">http://swift.im</a>\tfoo"), + result); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkifyTest); -- cgit v0.10.2-6-g49f6