Hi,
we are using DocumentBuilder#insertHtml
to insert MathML and it can happen that the alttext
attribute of the MathML node contains a “<
” entity. This will cause an exception (see stacktrace below) during the insertHtml
call. Since the exception mentions the character in it’s plain form (as “<”) I assume there is some incorrect decoding going on here.
We have reproduced this in the latest version of Aspose.Words (version 21.2).
Example program that reproduces this issue:
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import java.io.File;
public class MathMLAltTest {
public static void main(String[] args) throws Exception {
File dataDir = File.createTempFile("mathml-test", ".docx");
System.out.println(dataDir.toString());
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final String mathML = ""
+ "<math "
+ " xmlns=\"http://www.w3.org/1998/Math/MathML\""
+ " alttext=\"1 < 2\""
+ ">"
+ "<mrow><msub><mi>a</mi><mrow><mn>1</mn></mrow></msub><mo>+</mo><msub><mi>b</mi><mrow><mn>1</mn></mrow></msub></mrow>"
+ "</math>";
builder.insertHtml(mathML);
doc.save(dataDir.toString());
}
}
Stack trace:
Exception in thread "main" java.lang.IllegalStateException: XMLStreamException: Unexpected character '<' (code 60) in attribute value
at [row,col {unknown-source}]: [1,18]
at com.aspose.words.internal.zzZYQ.zzZ(Unknown Source)
at com.aspose.words.internal.zzZYQ.read(Unknown Source)
at com.aspose.words.internal.zzZYR.zzkZ(Unknown Source)
at com.aspose.words.internal.zzI4.<init>(Unknown Source)
at com.aspose.words.zzZ9Y.zzZ(Unknown Source)
at com.aspose.words.zzZN2.zzw(Unknown Source)
at com.aspose.words.zzZN2.zzZ(Unknown Source)
at com.aspose.words.zzZN2.zzY(Unknown Source)
at com.aspose.words.zzZN2.zzZ(Unknown Source)
at com.aspose.words.zzZN2.zzZ(Unknown Source)
at com.aspose.words.zzZPY.zzKO(Unknown Source)
at com.aspose.words.DocumentBuilder.zzZ(Unknown Source)
at com.aspose.words.DocumentBuilder.insertHtml(Unknown Source)
at MathMLAltTest.main(MathMLAltTest.java:55)
Caused by: com.aspose.words.internal.zzZUD: Unexpected character '<' (code 60) in attribute value
at [row,col {unknown-source}]: [1,18]
at com.aspose.words.internal.zzZTD.zzl(Unknown Source)
at com.aspose.words.internal.zzZTN.zzZ(Unknown Source)
at com.aspose.words.internal.zzZTN.zzXt(Unknown Source)
at com.aspose.words.internal.zzZTN.zzXv(Unknown Source)
at com.aspose.words.internal.zzZTN.zzXw(Unknown Source)
at com.aspose.words.internal.zzZTN.zzNS(Unknown Source)
at com.aspose.words.internal.zzZTN.next(Unknown Source)
at com.aspose.words.internal.zzZYQ.read(Unknown Source)
... 12 more