Fix bug with advancing the position when linkifying failed

This commit is contained in:
cketti 2017-03-17 15:19:16 +01:00
parent 0f9bc4867a
commit 98974a7699
2 changed files with 10 additions and 1 deletions

View file

@ -51,7 +51,7 @@ public class UriLinkifier {
boolean uriWasNotLinkified = newPos <= startPos; boolean uriWasNotLinkified = newPos <= startPos;
if (uriWasNotLinkified) { if (uriWasNotLinkified) {
outputBuffer.append(text.charAt(startPos)); outputBuffer.append(text.charAt(startPos));
currentPos++; currentPos = startPos + 1;
} else { } else {
currentPos = (newPos > currentPos) ? newPos : currentPos + 1; currentPos = (newPos > currentPos) ? newPos : currentPos + 1;
} }

View file

@ -115,4 +115,13 @@ public class UriLinkifierTest {
assertEquals("myhttp: <a href=\"http://example.org\">http://example.org</a>", outputBuffer.toString()); assertEquals("myhttp: <a href=\"http://example.org\">http://example.org</a>", outputBuffer.toString());
} }
@Test
public void schemaMatchWithInvalidUriInMiddleOfTextFollowedVyValidUri() throws Exception {
String text = "prefix http:42 http://example.org";
UriLinkifier.linkifyText(text, outputBuffer);
assertEquals("prefix http:42 <a href=\"http://example.org\">http://example.org</a>", outputBuffer.toString());
}
} }