Aspose.Words corrupts the hyperlink when updated content contains Unicode characters

Hello dear Aspose Team,

We recently encountered that Aspose.Words DLL harms the hyperlink when the Address property is being set to a folder with a name containing multiple Unicode characters.

The hyperlink address we are trying to update to

"\Test File\⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩\Parent File.docx"

The hyperlink address Aspose.Words updated to

"\Test File\⺀⺁⺂⺃¢£¤¥¦§¨©ª"

As a result of this, the links in our files are getting harmed and broken. Upon clicking to the link, Word is showing a messagebox that the link does not exist.

We’ve created a demo test project to demonstrate the behavior

https://files.axiomint.com/external/file/mg4r78fe30e3862e34e6a98434a4177b7c18e

In order to reproduce the issue

  1. Run the small console application.
  2. Notice that the reported updated link is truncated and not correct.
  3. Navigate to "bin\Debug\Test File\⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩" directory and manually make sure that the link in the “Parent File Updated.docx” file is corrupt.

@vahem Unfortunately, I cannot download the shared project. Could you please attach your input and output documents here in the forum? If forum does not allow uploading document, please zip them.

Hi Alexey,

I have uploaded the project to Google Drive as well, can you please try the following link?

https://drive.google.com/file/d/1kJoC0vdAVogU-GdGiZHp92YoxjF5Wlt-/view?usp=sharing

I’m also attaching the input and output files as you requested

Parent File Updated.docx (20.2 KB)

Parent File.docx (12.0 KB)

@vahem The file is infected and is not allowed to be downloaded:

So, please simply post the code that will allow us to reproduce the problem.

@alexey.noskov Sorry for that, I’m not sure why the file is being shown as infected. I will document some simplified steps of creating the test project below

  1. Create an empty .NET Framework Console project (I’ve referenced .NET framework 4.6.1).
  2. Add a reference to Aspose.Words 24.2 DLL.
  3. Create a folder named “Test File” in the root folder of the project.
  4. Create a subfolder named “⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩” in “Test File” folder.
  5. Place “Parent File.docx” file inside the “⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩” folder.
  6. Include “Test File” folder in the project from Visual Studio and set “Copy To Output Directory” to “Copy Always” for “Parent File.docx” file (right click → Properties" on those files.
  7. Update Program.cs with the following code and run the project. After running check the output files in “bin” folder.
using Aspose.Words;
using Aspose.Words.Fields;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AsposeWordUnicodePath
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string filePath = @"Test File\⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩\Parent File.docx";
            string absoluteFilePath = Path.GetFullPath(filePath);

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                var loadOptions = new Aspose.Words.Loading.LoadOptions();
                Document document = new Document(fs, loadOptions);

                foreach (Node node in document.Sections)
                {
                    if (!(node is Section section))
                        continue;

                    foreach (Field rangeField in section.Body.Range.Fields)
                    {
                        if (rangeField.Type == FieldType.FieldHyperlink)
                        {
                            FieldHyperlink hyperlink = (FieldHyperlink)rangeField;
                            if (hyperlink.Address == null)
                                continue;

                            Console.WriteLine("Old hyperlink address: " + hyperlink.Address);
                            Console.WriteLine("New hyperlink address: " + absoluteFilePath);
                            Console.WriteLine("Updating...");
                            hyperlink.Address = absoluteFilePath;
                            Console.WriteLine("Updated hyperlink address: " + hyperlink.Address);

                            string updatedFilePath = @"Test File\⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩\Parent File Updated.docx";
                            using (FileStream updatedFs = new FileStream(updatedFilePath, FileMode.OpenOrCreate))
                            {
                                document.Save(updatedFs, SaveFormat.Docx);
                            }
                        }
                    }
                }
            }

            Console.ReadKey();
        }
    }
}

Parent File.docx (12.0 KB)

@vahem
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26596

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

The issues you have found earlier (filed as WORDSNET-26596) have been fixed in this Aspose.Words for .NET 24.4 update also available on NuGet.

Dear Aspose team,

We are still able to reproduce the issue with Aspose.Words 24.4.
You can use the same sample project attached to this ticket to confirm that. The only thing that needs to be changed is the reference to Aspose.Words DLL.

Can you verify that the fix was really included in this release?

Best, Vahe.

@vahem I cannot reproduce the prpblem on my side using 24.4 version of Aspose.Words. here is code used for testing:

string absoluteFilePath = @"C:\Temp\tmp\⺀⺁⺂⺃¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹ÊËÌÍΑβγδεζηθικדהוזח؉؊ٓ٧٩\Parent File.docx";

Document document = new Document(@"C:\Temp\in.docx");

foreach (Field rangeField in document.Range.Fields)
{
    if (rangeField.Type == FieldType.FieldHyperlink)
    {
        FieldHyperlink hyperlink = (FieldHyperlink)rangeField;
        if (hyperlink.Address == null)
            continue;

        Console.WriteLine("Old hyperlink address: " + hyperlink.Address);
        Console.WriteLine("New hyperlink address: " + absoluteFilePath);
        Console.WriteLine("Updating...");
        hyperlink.Address = absoluteFilePath;
        Console.WriteLine("Updated hyperlink address: " + hyperlink.Address);
    }
}

document.Save(@"C:\Temp\out.docx");

Here is the produced output: out.docx (9.5 KB)

@alexey.noskov The hyperlink in the “out.docx” file seems truncated

Is it different on your machine?

@vahem It is not truncated. If you press Alt+F9 you will see the url is correct:

@alexey.noskov This is correct. Alt+F9 shows the correct URL. However

  • The hyperlink is not functional. Clicking on it does not open the file even when the file exists in that location.
  • Edit Hyperlink shows truncated hyperlink.

Please refer to the screenshots from my previous comment which are clearly showing these 2 points.

This does not seem to be a Microsoft Word issue. When I try to add a new hyperlink, it works correctly.

This leads us to believe that the issue is not fully fixed.

@vahem
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26835

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

@alexey.noskov Thanks a lot!

1 Like