From fce3f7606ba6fd9db45403755382e67e330ebaed Mon Sep 17 00:00:00 2001 From: Ivan Yatskevich Date: Tue, 18 Oct 2016 14:25:36 +0300 Subject: [PATCH] escape link text to be safely used in xml --- .../docx4j/convert/in/xhtml/XHTMLImporterImpl.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java b/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java index 2624bc9..799176e 100644 --- a/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java +++ b/src/main/java/org/docx4j/convert/in/xhtml/XHTMLImporterImpl.java @@ -48,6 +48,7 @@ import javax.xml.bind.JAXBException; import javax.xml.transform.Source; +import org.apache.commons.lang3.StringEscapeUtils; import org.docx4j.Docx4jProperties; import org.docx4j.UnitsOfMeasurement; import org.docx4j.XmlUtils; @@ -2164,13 +2165,10 @@ public void setBookmarkNamePrefix(String bookmarkNamePrefix) { private Hyperlink createHyperlink(String url, RPr rPr, String linkText, RelationshipsPart rp) { - - if (linkText.contains("&") - && !linkText.contains("&")) { - // escape them so we can unmarshall - linkText = linkText.replace("&", "&"); - } - + + // escape special characters so we can unmarshall + linkText = StringEscapeUtils.escapeXml10(linkText); + try { String hpl = null;