Free Support Forum - aspose.com

Bug in MailMerge handling of merge fields that are in IF condition

This happens in latest Aspose.Words .NET 9.1.0.0, Developer OEM Subscription.


The attached file contains a single field of type:
{ IF<!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:Standardowy; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

<![endif]–>"«myField»" <> “” “text when provided” “text when not provided” }

Some values for «myField» that contain an open parenthesis cause InvalidCastException to be thrown when executing the mailmerge.

The test methods in the following NUnit suite, that have a [ExpectedException(typeof(InvalidCastException))]
attribute contain the problematic values:





[Test]
[ExpectedException(typeof(InvalidCastException))]
public void Breaks1()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 (word2 word3)” });
}

[Test]
[ExpectedException(typeof(InvalidCastException))]
public void Breaks2()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new[] { “myField” }, new[] { “(word1 word2)” });
}


[Test]
public void One_Word_In_Parenthesis_Works()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 (word2)” });
}

[Test]
public void Tabs_As_Separator_In_Parenthesis_Work()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new[] { “myField” }, new[] { “word1 (word2\tword3)” });
}

[Test]
public void One_Word_In_Parenthesis_With_Preceding_Space_Works()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 ( word2)” });
}

[Test]
public void One_Word_In_Parenthesis_With_Following_Space_Works()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 (word2 )” });
}

[Test]
public void One_Word_In_Parenthesis_With_Following_And_Preceding_Space_Works()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new[] { “myField” }, new[] { “word1 ( word2 )” });
}

[Test]
public void One_Space_In_Parenthesis_Works()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 ( )” });
}

[Test]
public void Empty_Parenthesis_Works()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 ()” });
}

[Test]
[ExpectedException(typeof(InvalidCastException))]
public void Breaks3()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 (word2” });
}

[Test]
[ExpectedException(typeof(InvalidCastException))]
public void Breaks4()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “(word2” });
}

[Test]
public void FixType1_Works1()
{
// Uses Zero Width Space
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “word1 \u200B(word2 word3)” });
}


[Test]
[ExpectedException(typeof(InvalidCastException))]
public void FixType1_Doesnt_Work()
{
// Uses Zero Width Space
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “\u200B(word1 word2)” });
}


[Test]
public void FixType2_Works_And_Changes_Only_Spaces_Breakability()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “(word1\u00A0word2)” });
}

[Test]
[ExpectedException(typeof(InvalidCastException))]
public void FixType2_Doesnt_Work()
{
// uses a no-break space
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “(word1\u00A0word2” });
}

[Test]
public void FixType2_Works_And_Changes_Only_Spaces_Width_To_Fixed()
{
// uses a Four-Per-Em Space, Mid Space from http://en.wikipedia.org/wiki/Space_(punctuation)
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “(word1\u2005word2)” });
}

[Test]
public void FixType3_Works_But_Changes_Content()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “\u200B \u200B(word1 word2)” });
}

[Test]
public void FixType3_Is_A_Universal_Solution_But_Changes_Content()
{
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “\u200B \u200B(word1” });
}

[Test]
[ExpectedException(typeof(InvalidCastException))]
public void FixType3_With_Different_Spaces_Dont_Work()
{
/* tried some zero-width or thinner spaces and none works:
* Zero Width Non Joiner 200D,
* Zero Width Joiner (ZWJ) 200D,
* Zero Width No-Break Space (Byte Order Mark) FEFF
* Thin Space 2009
* Punctuation Space 2008
* Six-Per-Em Space 2006
* Three-Per-Em Space (Thick Space) 2004
*/
var myFile = CommonEmbeddedTestTemplate.Test_Aspose_exception;
new Document(myFile.GetStream()).MailMerge.Execute(new [] {“myField”}, new [] { “\u200B\u2006\u200B(word1 word2)” });
}


Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for reporting this problem to us. I managed to reproduce it on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards.

The issues you have found earlier (filed as 16662) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.