diff options
| author | Remko Tronçon <git@el-tramo.be> | 2009-11-18 20:49:42 (GMT) |
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2009-11-18 20:49:42 (GMT) |
| commit | b6594d2bdd57bf786fcc62a35f8e837ba8d221cc (patch) | |
| tree | 830a0900d3dbfd8a7eaf8239ca6243b7ff9f1be5 | |
| parent | 013725b6ac01ee0351cd61701588099dc1ec1258 (diff) | |
| download | swift-b6594d2bdd57bf786fcc62a35f8e837ba8d221cc.zip swift-b6594d2bdd57bf786fcc62a35f8e837ba8d221cc.tar.bz2 | |
Fix linkifying of urls with #.
| -rw-r--r-- | SwifTools/Linkify.cpp | 2 | ||||
| -rw-r--r-- | SwifTools/UnitTest/LinkifyTest.cpp | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/SwifTools/Linkify.cpp b/SwifTools/Linkify.cpp index 8cc169b..7fa8c91 100644 --- a/SwifTools/Linkify.cpp +++ b/SwifTools/Linkify.cpp @@ -1,13 +1,13 @@ #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>", diff --git a/SwifTools/UnitTest/LinkifyTest.cpp b/SwifTools/UnitTest/LinkifyTest.cpp index b55067c..b31bbfe 100644 --- a/SwifTools/UnitTest/LinkifyTest.cpp +++ b/SwifTools/UnitTest/LinkifyTest.cpp @@ -11,12 +11,13 @@ class LinkifyTest : public CppUnit::TestFixture { 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_SUITE_END(); public: void testLinkify_URLWithResource() { String result = Linkify::linkify("http://swift.im/blog"); @@ -70,9 +71,17 @@ class LinkifyTest : public CppUnit::TestFixture { String result = Linkify::linkify("http://foo.com/bar/baz/"); CPPUNIT_ASSERT_EQUAL( String("<a href=\"http://foo.com/bar/baz/\">http://foo.com/bar/baz/</a>"), result); } + + void testLinkify_Anchor() { + String result = Linkify::linkify("http://foo.com/bar#baz"); + + CPPUNIT_ASSERT_EQUAL( + String("<a href=\"http://foo.com/bar#baz\">http://foo.com/bar#baz</a>"), + result); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkifyTest); |
Swift