You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Issue #3871] File activation for unpackaged App would fail when file path contains unicode characters or special characters (#5175)
* Add special logic to use string operations for file uri parsing
* minor refactor to increase readability and simplify logic
* Add test
* refine comments
* Add description on error
// By design parsed query should have a size of 3 (ContractId, Verb, File), in which case result from QueryParsed() can be used directly.
53
+
// However, it may have a size of 0 when uri contains unicode characters, or more than 3 when file path contains "&", which requires manual parsing with string functions.
54
+
if (parsedQuery.Size() == 3)
55
+
{
56
+
auto verb = parsedQuery.GetFirstValueByName(L"Verb");
57
+
auto file = parsedQuery.GetFirstValueByName(L"File");
58
+
return make<FileActivatedEventArgs>(verb, file);
59
+
}
60
+
61
+
const std::wstring query = uri.Query().c_str();
62
+
auto queryLength = query.length();
63
+
64
+
auto verbBegin = query.find(L"&Verb=");
65
+
if (verbBegin == std::wstring::npos)
66
+
{
67
+
throwwinrt::hresult_invalid_argument(L"Query of encoded file protocol should contain 'Verb'");
68
+
}
69
+
verbBegin += 6; // Length of "&Verb="
70
+
71
+
auto verbEnd = query.find(L"&", verbBegin);
72
+
if (verbEnd == std::wstring::npos)
73
+
{
74
+
verbEnd = queryLength;
75
+
}
76
+
77
+
auto fileBegin = query.find(L"&File=");
78
+
if (fileBegin == std::wstring::npos)
79
+
{
80
+
throwwinrt::hresult_invalid_argument(L"Query of encoded file protocol should contain 'File'");
81
+
}
82
+
fileBegin += 6; // Length of "&File="
83
+
84
+
// File path may contain '&' character, so fileEnd can only be assumed to be the end of the query or start of Verb
85
+
auto fileEnd = verbBegin > fileBegin ? verbBegin : queryLength;
86
+
87
+
auto verb = winrt::to_hstring(query.substr(verbBegin, verbEnd - verbBegin).c_str());
88
+
auto file = winrt::to_hstring(query.substr(fileBegin, fileEnd - fileBegin).c_str());
0 commit comments