Skip to content

Commit 33de0b2

Browse files
[vs17.9] [ClickOnce] [GB18030] Workaround for incorrect encoding of chars in the PUA range of file paths (#9669)
* ClickOnce GB18030: Workaround for incorrect encoding of chars in the PUA range of file paths * Bump version * C/R-update comment --------- Co-authored-by: Jan Krivanek <[email protected]>
1 parent 90725d0 commit 33de0b2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
33
<Project>
44
<PropertyGroup>
5-
<VersionPrefix>17.9.4</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
5+
<VersionPrefix>17.9.5</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
66
<PackageValidationBaselineVersion>17.8.3</PackageValidationBaselineVersion>
77
<AssemblyVersion>15.1.0.0</AssemblyVersion>
88
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>

src/Tasks/ManifestUtil/PathUtil.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ public static string Format(string path)
4545

4646
string resolvedPath = Resolve(path);
4747
Uri u = new Uri(resolvedPath);
48+
//
49+
// GB18030: Uri class does not correctly encode chars in the PUA range for implicit
50+
// file paths (paths without explicit scheme):
51+
// https://github.com/dotnet/runtime/issues/89538
52+
// Workaround is to use UriBuilder with the file scheme specified explicitly to
53+
// correctly encode the PUA chars.
54+
//
55+
if (Uri.UriSchemeFile.Equals(u.Scheme, StringComparison.OrdinalIgnoreCase) &&
56+
!IsAsciiString(resolvedPath))
57+
{
58+
UriBuilder builder = new UriBuilder()
59+
{
60+
Scheme = Uri.UriSchemeFile,
61+
Host = string.Empty,
62+
Path = resolvedPath,
63+
};
64+
u = builder.Uri;
65+
}
4866
return u.AbsoluteUri;
4967
}
5068

@@ -209,5 +227,15 @@ public static string Resolve(string path)
209227
// if not unc or url then it must be a local disk path...
210228
return Path.GetFullPath(path); // make sure it's a full path
211229
}
230+
231+
private static bool IsAsciiString(string str)
232+
{
233+
foreach (char c in str)
234+
{
235+
if (c > 127)
236+
{ return false; }
237+
}
238+
return true;
239+
}
212240
}
213241
}

0 commit comments

Comments
 (0)