diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-01-29 23:53:50 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-01-29 23:53:50 (GMT) |
commit | c7e907730e98176be0fdd4e484f2a903b4228348 (patch) | |
tree | 21139f5ccad144e7bba3472954d94a28c14bb3d4 | |
parent | 01f868c4040234ed4b1ee7d0e08377a89b928b77 (diff) | |
download | swift-c7e907730e98176be0fdd4e484f2a903b4228348.zip swift-c7e907730e98176be0fdd4e484f2a903b4228348.tar.bz2 |
Fix tilde in links
-rw-r--r-- | SwifTools/Linkify.cpp | 2 | ||||
-rw-r--r-- | SwifTools/UnitTest/LinkifyTest.cpp | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/SwifTools/Linkify.cpp b/SwifTools/Linkify.cpp index 63f06c8..48162e1 100644 --- a/SwifTools/Linkify.cpp +++ b/SwifTools/Linkify.cpp @@ -1,17 +1,17 @@ #include "SwifTools/Linkify.h" #include <boost/regex.hpp> namespace Swift { -static const boost::regex linkifyRegexp("(https?://([\\-\\w\\.]+)+(:\\d+)?(/([%\\-\\w/_#\\.\\+]*(\\?\\S+)?)?)?)"); +static const boost::regex linkifyRegexp("(https?://([\\-\\w\\.]+)+(:\\d+)?(/([%~\\-\\w/_#\\.\\+]*(\\?\\S+)?)?)?)"); String Linkify::linkify(const String& input) { return String(boost::regex_replace( input.getUTF8String(), linkifyRegexp, "<a href=\"\\1\">\\1</a>", boost::match_default|boost::format_all)); } } diff --git a/SwifTools/UnitTest/LinkifyTest.cpp b/SwifTools/UnitTest/LinkifyTest.cpp index e952585..6e27c2c 100644 --- a/SwifTools/UnitTest/LinkifyTest.cpp +++ b/SwifTools/UnitTest/LinkifyTest.cpp @@ -1,66 +1,67 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include "SwifTools/Linkify.h" using namespace Swift; class LinkifyTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(LinkifyTest); CPPUNIT_TEST(testLinkify_URLWithResource); CPPUNIT_TEST(testLinkify_URLWithEmptyResource); CPPUNIT_TEST(testLinkify_BareURL); CPPUNIT_TEST(testLinkify_URLSurroundedByWhitespace); CPPUNIT_TEST(testLinkify_MultipleURLs); CPPUNIT_TEST(testLinkify_CamelCase); CPPUNIT_TEST(testLinkify_HierarchicalResource); CPPUNIT_TEST(testLinkify_Anchor); CPPUNIT_TEST(testLinkify_Plus); + CPPUNIT_TEST(testLinkify_Tilde); CPPUNIT_TEST_SUITE_END(); public: void testLinkify_URLWithResource() { String result = Linkify::linkify("http://swift.im/blog"); CPPUNIT_ASSERT_EQUAL( String("<a href=\"http://swift.im/blog\">http://swift.im/blog</a>"), result); } void testLinkify_URLWithEmptyResource() { String result = Linkify::linkify("http://swift.im/"); CPPUNIT_ASSERT_EQUAL( String("<a href=\"http://swift.im/\">http://swift.im/</a>"), result); } void testLinkify_BareURL() { String result = Linkify::linkify("http://swift.im"); CPPUNIT_ASSERT_EQUAL( String("<a href=\"http://swift.im\">http://swift.im</a>"), result); } void testLinkify_URLSurroundedByWhitespace() { String result = Linkify::linkify("Foo http://swift.im/blog Bar"); CPPUNIT_ASSERT_EQUAL( String("Foo <a href=\"http://swift.im/blog\">http://swift.im/blog</a> Bar"), result); } void testLinkify_MultipleURLs() { String result = Linkify::linkify("Foo http://swift.im/blog Bar http://el-tramo.be/about Baz"); CPPUNIT_ASSERT_EQUAL( String("Foo <a href=\"http://swift.im/blog\">http://swift.im/blog</a> Bar <a href=\"http://el-tramo.be/about\">http://el-tramo.be/about</a> Baz"), result); } void testLinkify_CamelCase() { String result = Linkify::linkify("http://fOo.cOm/bAz"); CPPUNIT_ASSERT_EQUAL( |