Skip to content

Commit

Permalink
[vs17.9] [ClickOnce] [GB18030] Workaround for incorrect encoding of c…
Browse files Browse the repository at this point in the history
…hars 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 <krivanek.j@hotmail.com>
  • Loading branch information
sujitnayak and JanKrivanek committed Jan 26, 2024
1 parent 90725d0 commit 33de0b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eng/Versions.props
Expand Up @@ -2,7 +2,7 @@
<!-- 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. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.9.4</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<VersionPrefix>17.9.5</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.8.3</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
Expand Down
28 changes: 28 additions & 0 deletions src/Tasks/ManifestUtil/PathUtil.cs
Expand Up @@ -45,6 +45,24 @@ public static string Format(string path)

string resolvedPath = Resolve(path);
Uri u = new Uri(resolvedPath);
//
// GB18030: Uri class does not correctly encode chars in the PUA range for implicit
// file paths (paths without explicit scheme):
// https://github.com/dotnet/runtime/issues/89538
// Workaround is to use UriBuilder with the file scheme specified explicitly to
// correctly encode the PUA chars.
//
if (Uri.UriSchemeFile.Equals(u.Scheme, StringComparison.OrdinalIgnoreCase) &&
!IsAsciiString(resolvedPath))
{
UriBuilder builder = new UriBuilder()
{
Scheme = Uri.UriSchemeFile,
Host = string.Empty,
Path = resolvedPath,
};
u = builder.Uri;
}
return u.AbsoluteUri;
}

Expand Down Expand Up @@ -209,5 +227,15 @@ public static string Resolve(string path)
// if not unc or url then it must be a local disk path...
return Path.GetFullPath(path); // make sure it's a full path
}

private static bool IsAsciiString(string str)
{
foreach (char c in str)
{
if (c > 127)
{ return false; }
}
return true;
}
}
}

0 comments on commit 33de0b2

Please sign in to comment.