Skip to content

Commit 4f94f3e

Browse files
authored
Fix portable installer issues when installing to non ascii path (#5788)
Fixes issue raised in the [comment](#473 (comment)) The utf8 string needs to be converted to utf16 string before assigning to std::filesystem::path. Verified manually. Added e2e tests. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5788)
1 parent 8ea16f8 commit 4f94f3e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/AppInstallerCLIE2ETests/UpgradeCommand.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ public void UpgradePortable()
4949
TestCommon.VerifyPortablePackage(Path.Combine(installDir, packageDirName), commandAlias, fileName, productCode, true);
5050
}
5151

52+
/// <summary>
53+
/// Test upgrade portable package.
54+
/// </summary>
55+
[Test]
56+
public void UpgradePortableNonAsciiPath()
57+
{
58+
string installDir = Path.Combine(TestCommon.GetRandomTestDir(), "Tést");
59+
string packageId, commandAlias, fileName, productCode;
60+
packageId = "AppInstallerTest.TestPortableExe";
61+
productCode = packageId + "_" + Constants.TestSourceIdentifier;
62+
commandAlias = fileName = "AppInstallerTestExeInstaller.exe";
63+
64+
var result = TestCommon.RunAICLICommand("install", $"AppInstallerTest.TestPortableExe -v 1.0.0.0 -l {installDir}");
65+
Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
66+
Assert.True(result.StdOut.Contains("Successfully installed"));
67+
68+
var result2 = TestCommon.RunAICLICommand("upgrade", $"{packageId} -v 2.0.0.0 -l {installDir}");
69+
Assert.AreEqual(Constants.ErrorCode.S_OK, result2.ExitCode);
70+
Assert.True(result2.StdOut.Contains("Successfully installed"));
71+
TestCommon.VerifyPortablePackage(installDir, commandAlias, fileName, productCode, true);
72+
}
73+
5274
/// <summary>
5375
/// Test upgrade portable package with arp mismatch.
5476
/// </summary>

src/AppInstallerRepositoryCore/Microsoft/Schema/Portable_1_0/PortableTable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace AppInstaller::Repository::Microsoft::Schema::Portable_V1_0
108108
{
109109
auto [filePath, fileType, sha256, symlinkTarget] = select.GetRow<std::string, Portable::PortableFileType, std::string, std::string>();
110110
portableFile.FileType = fileType;
111-
portableFile.SetFilePath(std::move(filePath));
111+
portableFile.SetFilePath(Utility::ConvertToUTF16(filePath));
112112
portableFile.SHA256 = std::move(sha256);
113113
portableFile.SymlinkTarget = std::move(symlinkTarget);
114114
return portableFile;
@@ -167,12 +167,12 @@ namespace AppInstaller::Repository::Microsoft::Schema::Portable_V1_0
167167
Portable::PortableFileEntry portableFile;
168168
auto [filePath, fileType, sha256, symlinkTarget] = select.GetRow<std::string, Portable::PortableFileType, std::string, std::string>();
169169
portableFile.FileType = fileType;
170-
portableFile.SetFilePath(std::move(filePath));
170+
portableFile.SetFilePath(Utility::ConvertToUTF16(filePath));
171171
portableFile.SHA256 = std::move(sha256);
172172
portableFile.SymlinkTarget = std::move(symlinkTarget);
173173
result.emplace_back(std::move(portableFile));
174174
}
175175

176176
return result;
177177
}
178-
}
178+
}

0 commit comments

Comments
 (0)