dotnet / dotnet/wpf

Loading, saving and loading RTF leads to exception

Open
#7,601 4 comments 1 reaction 1 assignee Claimed by @dipeshmsft View on GitHub
:construction: work in progress Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

Loading some RTF in a `RichTextBox`, saving it and loading it again causes an exception to be thrown.

This happens because the RTF contains a hyperlink which contains an umlaut ("ö" in this example).
That umlaut is correctly escaped in the source RTF with "\'f6".
Loading the source RTF works fine.
Saving the RTF with `RichTextBox` causes the correctly escaped text to become `'f6`.
Loading this again causes an exception while trying to construct the NavigationUri, as an unescaped "'" is not valid in an URI.

After some investigation the issue seems to be that:
XamlToRtfWriter.WriteInlineChild calls BamlResourceContentUtil.UnescapeString which then simply removes the "\\" before the "'", thus producing an invalid URI.

One way to solve this would be to add
```
else if (documentNode.NavigateUri[i] == "'")
{
_rtfBuilder.Append("\\'");
}
```

### Reproduction Steps

See attached repro project.
[UmlautIssue.zip](https://github.com/dotnet/wpf/files/10918031/UmlautIssue.zip)

### Expected behavior

No exception should occur and RTF should be rendered.

### Actual behavior

Exception is thrown during load (after save from `RichTextBox`).

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

Tested with .NET 4.8 and .NET 6.0.

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.