We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

InsertHtml does not decode HTML entities in URLs in hyperlinks

Hi,

I am using DocumentBuilder to create a document and have a problem when inserting hyperlinks. This fragment demonstrates the problem.

// builder is a DocumentBuilder from somewhere
builder.InsertHtml("<a href=“http://www.google.co.uk/search?hl=en-GB&q=pictures+of+cats”>Google for cat pictures");
Notice that the query of the URL in the contains the HTML entity & rather than the ampersand character as it has come from an XHTML document. Aspose.Words does not decode this entity so the document ends up with a URL that does not work:
http://www.google.co.uk/search?hl=en-GB&q=pictures+of+cats
The correct URL is, of course:
http://www.google.co.uk/search?hl=en-GB&q=pictures+of+cats
Can you suggest a workaround or provide a fix?

Thanks,
Alex.

Hi

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

Thanks for your inquiry. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

As a temporary workaround, you can try using the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

string html = "Google for cat pictures";

// Create regular expression, which will match urls.

Regex urlRegex = new Regex("HREF\\s*=\\s*[\"']?([^\"'>]+?)[\"']", RegexOptions.IgnoreCase);

// Find all urls and replace & with &.

MatchCollection matches = urlRegex.Matches(html);

foreach (Match match in matches)

html = html.Replace(match.Groups[1].Value, match.Groups[1].Value.Replace("&", "&"));

// Insert html.

builder.InsertHtml(html);

doc.Save(@"Test001\out.doc");

Hope this helps.

Best regards.

Hi Alexey,



Do you have any updates on the availability of the fix?



Thanks,

Alex.

Hi Alex,

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

Thanks for your request. This issue is also resolved in the current code base. The fix will be included into the next hotfix, which will be released approximately in a week. You will be notified.

Best regards.

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


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