InsertHtml throws java.lang.IllegalStateException using Java | MathML

Hi,

we are using DocumentBuilder#insertHtml to insert MathML and it can happen that the alttext attribute of the MathML node contains a “&lt;” 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 &lt; 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

@thomask15t

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-21794. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@tahir.manzoor - do you have an ETA for when this bug might be fixed? Thanks, Thomas.

@TR-K15t

Currently, this issue is under development phase. Hopefully, you will get the fix of this issue in the next version of Aspose.Words i.e. 21.5. We will inform you via this forum thread once this issue is resolved.

@tahir.manzoor - perfect, thanks for the update.

The issues you have found earlier (filed as WORDSNET-21794) have been fixed in this Aspose.Words for .NET 21.5 update and this Aspose.Words for Java 21.5 update.