Index: test/com/opensymphony/util/TextUtilsTest.java
===================================================================
--- test/com/opensymphony/util/TextUtilsTest.java (revision 147)
+++ test/com/opensymphony/util/TextUtilsTest.java (working copy)
@@ -115,6 +115,11 @@
assertEquals(""test"", TextUtils.htmlEncode("\"test\""));
assertEquals("\u0445test\u0445", TextUtils.htmlEncode("\u0445test\u0445"));
assertEquals("\u0445\u0642test\u0445", TextUtils.htmlEncode("\u0445\u0642test\u0445"));
+
+ String input = "http://www.xxx.com/getStuff?stuff_id=12&readonly=true";
+ String expectedResult = "http://www.xxx.com/getStuff?stuff_id=12&readonly=true";
+ assertEquals(expectedResult, TextUtils.htmlEncode(input));
+
}
public void testHyperLink() {
@@ -210,6 +215,28 @@
//problem with the whole string not being linked if the last url is 'http://' - CORE-65
assertEquals("http://testUrl http:// ", TextUtils.linkURL("http://testUrl http:// "));
+
+ // colon is legal in the path component
+ _testLinkUrl("http://foo.com/bar:baz");
+
+ // dot on the end of a url is interpreted as a full stop for the sentence.
+ assertEquals("Check out http://www.somewhere.com/foobar.", TextUtils.linkURL("Check out http://www.somewhere.com/foobar."));
+ // this is a way of putting the dot on the end of a url
+ assertEquals("Check out 'http://www.somewhere.com/url-ending-in-dot.'", TextUtils.linkURL("Check out 'http://www.somewhere.com/url-ending-in-dot.'"));
+ // full stop should be removed
+ assertEquals("Check out 'http://www.somewhere.com'.", TextUtils.linkURL("Check out 'http://www.somewhere.com'."));
+
+ // CORE-76 trailing legal URL characters ':' '-' '~' should be included unlike "." which is still guessed to be a full stop
+ _testLinkUrl("http://foo.com/bar:");
+ _testLinkUrl("http://something.com/ending-in-minus-");
+ _testLinkUrl("http://something.com/ending-in-tilda~");
+ assertEquals("http://something.com/ending-in-minus-", TextUtils.linkURL("http://something.com/ending-in-minus-"));
+ assertEquals("http://something.com/ending-in-tilda~", TextUtils.linkURL("http://something.com/ending-in-tilda~"));
+
+ // TODO: what about making these work?
+// assertEquals("(yep http://www.opensymphony.com/)", TextUtils.linkURL("(yep http://www.opensymphony.com/)")); //brackets test
+// assertEquals("(yep http://www.opensymphony.com)", TextUtils.linkURL("(yep http://www.opensymphony.com)")); //brackets test
+// assertEquals("(see http://something.com/ending-in-minus-)", TextUtils.linkURL("(see http://something.com/ending-in-minus-)"));
}
public void testNulls() {
@@ -250,6 +277,11 @@
String input = "12;";
String expectedResult = "<foo rdf:datatype="http://abc.com">12;</foo>";
assertEquals(expectedResult, TextUtils.plainTextToHtml(input));
+
+ input = "http://www.xxx.com/getStuff?stuff_id=12&readonly=true";
+ expectedResult = "http://www.xxx.com/getStuff?stuff_id=12&readonly=true";
+ assertEquals(expectedResult, TextUtils.plainTextToHtml(input));
+
}
public void testVerifyEmail() {
Index: java/com/opensymphony/util/TextUtils.java
===================================================================
--- java/com/opensymphony/util/TextUtils.java (revision 147)
+++ java/com/opensymphony/util/TextUtils.java (working copy)
@@ -894,15 +894,12 @@
//Decrement linkEndIndex back by 1 to reflect the real ending index position of the URL...
linkEndIndex--;
- //If the last chars of urlStr is a '.', ':', '-', '/' or '~' then we exclude those chars.
- //The '.' at the end could be just a fullstop to a sentence and we don't want
- //that to be part of an url (which would then be invalid).
- //Pretty much the same for the other symbols - we don't want them at the end of any url
- //cos' this would stuff the url up.
+ // If the last char of urlStr is a '.' we exclude it. It is most likely a full stop and
+ // we don't want that to be part of an url.
while (true) {
char lastChar = urlStr.charAt(urlStr.length() - 1);
- if ((lastChar == '.') || (lastChar == ':') || (lastChar == '-') || (lastChar == '~')) {
+ if (lastChar == '.') {
urlStr = urlStr.substring(0, urlStr.length() - 1);
linkEndIndex--;
} else {