summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-23 17:41:17 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-23 17:41:17 (GMT)
commitb8aa124f6baa0c0a32ccfd7479fa1e6f0dff3487 (patch)
tree3472d3424d9ab67bdc51eeb35b92c9bd86619306
parent1e0c7d5c9d53ee6678a5f27d554710e6ae56d2da (diff)
downloadswift-b8aa124f6baa0c0a32ccfd7479fa1e6f0dff3487.zip
swift-b8aa124f6baa0c0a32ccfd7479fa1e6f0dff3487.tar.bz2
Fix linkifying links with '+'.
-rw-r--r--SwifTools/Linkify.cpp2
-rw-r--r--SwifTools/UnitTest/LinkifyTest.cpp9
2 files changed, 10 insertions, 1 deletions
diff --git a/SwifTools/Linkify.cpp b/SwifTools/Linkify.cpp
index 7fa8c91..63f06c8 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 b31bbfe..6c5fb15 100644
--- a/SwifTools/UnitTest/LinkifyTest.cpp
+++ b/SwifTools/UnitTest/LinkifyTest.cpp
@@ -1,87 +1,96 @@
#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_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(
String("<a href=\"http://fOo.cOm/bAz\">http://fOo.cOm/bAz</a>"),
result);
}
void testLinkify_HierarchicalResource() {
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);
}
+
+ void testLinkify_Plus() {
+ 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);