Commit fd53d22c authored by Michael Hamann's avatar Michael Hamann
Browse files

XRENDERING-612: Mailto links are incorrectly parsed

* Recognize mailto: links in XHTMLXWikiGeneratorListener
* Add the test case from XRENDERING-612
parent c28ff532
......@@ -66,6 +66,13 @@ public class XHTMLXWikiGeneratorListener extends DefaultXWikiGeneratorListener
*/
private static final Pattern URL_SCHEME_PATTERN = Pattern.compile("[a-zA-Z0-9+.-]*://");
/**
* Prefix for mailto-links.
*
* @since 14.0RC1
*/
private static final String MAILTO_PREFIX = "mailto:";
private static final String CLASS_ATTRIBUTE = "class";
/**
......@@ -142,7 +149,9 @@ public void onImage(WikiReference reference)
* <ul>
* <li>UC1: the reference points to a valid URL, we return a reference of type "url",
* e.g. {@code http://server/path/reference#anchor}</li>
* <li>UC2: the reference is not a valid URL, we return a reference of type "path",
* <li>UC2: the reference is a mailto: link, we return a reference of type "mailto",
* e.g., {@code mailto:user@example.com}</li>
* <li>UC3: the reference is not a valid URL, we return a reference of type "path",
* e.g. {@code path/reference#anchor}</li>
* </ul>
*
......@@ -158,8 +167,11 @@ private ResourceReference computeResourceReference(String rawReference)
if (matcher.lookingAt()) {
// We have UC1
reference = new ResourceReference(rawReference, ResourceType.URL);
} else {
} else if (rawReference.startsWith(MAILTO_PREFIX)) {
// We have UC2
reference = new ResourceReference(rawReference.substring(MAILTO_PREFIX.length()), ResourceType.MAILTO);
} else {
// We have UC3
reference = new ResourceReference(rawReference, ResourceType.PATH);
}
......
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<p>one <a href="mailto:john@doe.com">two</a> three</p>
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginParagraph
onWord [one]
onSpace
beginLink [Typed = [true] Type = [mailto] Reference = [john@doe.com]] [false]
onWord [two]
endLink [Typed = [true] Type = [mailto] Reference = [john@doe.com]] [false]
onSpace
onWord [three]
endParagraph
endDocument
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment