Skip to content

Commit 37e6139

Browse files
committed
Correct logging url
1 parent 67291a3 commit 37e6139

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

packages/url_launcher/url_launcher_windows/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.4
2+
3+
* Fixes an issue where the URL logged would not be escaped on failure.
4+
15
## 3.1.3
26

37
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

packages/url_launcher/url_launcher_windows/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher_windows
22
description: Windows implementation of the url_launcher plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_windows
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
5-
version: 3.1.3
5+
version: 3.1.4
66

77
environment:
88
sdk: ^3.3.0

packages/url_launcher/url_launcher_windows/windows/test/url_launcher_windows_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using flutter::EncodableMap;
2424
using flutter::EncodableValue;
2525
using ::testing::_;
2626
using ::testing::DoAll;
27+
using ::testing::HasSubstr;
2728
using ::testing::Pointee;
2829
using ::testing::Return;
2930
using ::testing::SetArgPointee;
@@ -160,5 +161,28 @@ TEST(UrlLauncherPlugin, LaunchUTF8EncodedFileURLSuccess) {
160161
EXPECT_TRUE(result.value());
161162
}
162163

164+
TEST(UrlLauncherPlugin, LaunchUTF8LogsUnescapedOnFail) {
165+
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
166+
167+
// Return a failure value (<32) from launching.
168+
EXPECT_CALL(
169+
*system,
170+
ShellExecuteW(
171+
_, StrEq(L"open"),
172+
// 家の管理/スキャナ"),
173+
StrEq(
174+
L"file:///G:/\x5bb6\x306e\x7ba1\x7406/\x30b9\x30ad\x30e3\x30ca"),
175+
_, _, _))
176+
.WillOnce(Return(reinterpret_cast<HINSTANCE>(0)));
177+
178+
UrlLauncherPlugin plugin(std::move(system));
179+
ErrorOr<bool> result = plugin.LaunchUrl(
180+
"file:///G:/%E5%AE%B6%E3%81%AE%E7%AE%A1%E7%90%86/"
181+
"%E3%82%B9%E3%82%AD%E3%83%A3%E3%83%8A");
182+
183+
ASSERT_TRUE(result.has_error());
184+
EXPECT_THAT(result.error().message(), HasSubstr("家の管理/スキャナ"));
185+
}
186+
163187
} // namespace test
164188
} // namespace url_launcher_windows

packages/url_launcher/url_launcher_windows/windows/url_launcher_plugin.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ErrorOr<bool> UrlLauncherPlugin::CanLaunchUrl(const std::string& url) {
9999
}
100100

101101
ErrorOr<bool> UrlLauncherPlugin::LaunchUrl(const std::string& url) {
102-
std::wstring url_wide;
102+
std::string url_to_open;
103103
if (url.find("file:") == 0) {
104104
// ShellExecuteW does not process %-encoded UTF8 strings in file URLs.
105105
DWORD unescaped_len = 0;
@@ -108,14 +108,15 @@ ErrorOr<bool> UrlLauncherPlugin::LaunchUrl(const std::string& url) {
108108
&unescaped_len, URL_UNESCAPE_INPLACE))) {
109109
return FlutterError("open_error", "Failed to unescape file URL");
110110
}
111-
url_wide = Utf16FromUtf8(unescaped_url);
111+
url_to_open = unescaped_url;
112112
} else {
113-
url_wide = Utf16FromUtf8(url);
113+
url_to_open = url;
114114
}
115115

116-
int status = static_cast<int>(reinterpret_cast<INT_PTR>(
117-
system_apis_->ShellExecuteW(nullptr, TEXT("open"), url_wide.c_str(),
118-
nullptr, nullptr, SW_SHOWNORMAL)));
116+
int status =
117+
static_cast<int>(reinterpret_cast<INT_PTR>(system_apis_->ShellExecuteW(
118+
nullptr, TEXT("open"), Utf16FromUtf8(url_to_open).c_str(), nullptr,
119+
nullptr, SW_SHOWNORMAL)));
119120

120121
// Per ::ShellExecuteW documentation, anything >32 indicates success.
121122
if (status <= 32) {
@@ -126,8 +127,8 @@ ErrorOr<bool> UrlLauncherPlugin::LaunchUrl(const std::string& url) {
126127
return false;
127128
}
128129
std::ostringstream error_message;
129-
error_message << "Failed to open " << url << ": ShellExecute error code "
130-
<< status;
130+
error_message << "Failed to open " << url_to_open
131+
<< ": ShellExecute error code " << status;
131132
return FlutterError("open_error", error_message.str());
132133
}
133134
return true;

0 commit comments

Comments
 (0)