Skip to content

Commit

Permalink
Correctly encode URLs according to RFC3986
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strickroth <email@cs-ware.de>
  • Loading branch information
csware committed Nov 14, 2020
1 parent e50e567 commit 8b74f96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/TortoiseProc/ProjectProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,18 @@ void ProjectProperties::ReplaceBugIDPlaceholder(CString& url, const CString& sBu
DWORD size = INTERNET_MAX_URL_LENGTH;
UrlEscape(sBugID, CStrBuf(parameter, size + 1), &size, URL_ESCAPE_SEGMENT_ONLY | URL_ESCAPE_PERCENT | URL_ESCAPE_AS_UTF8);
// UrlEscape does not escape + and =, starting with Win8 the URL_ESCAPE_ASCII_URI_COMPONENT flag could be used and the following two lines would not be necessary
parameter.Replace(L"!", L"%21");
parameter.Replace(L"$", L"%24");
parameter.Replace(L"'", L"%27");
parameter.Replace(L"(", L"%28");
parameter.Replace(L")", L"%29");
parameter.Replace(L"*", L"%2A");
parameter.Replace(L"+", L"%2B");
parameter.Replace(L",", L"%2C");
parameter.Replace(L":", L"%3A");
parameter.Replace(L";", L"%3B");
parameter.Replace(L"=", L"%3D");
parameter.Replace(L"@", L"%40");
url.Replace(L"%BUGID%", parameter);
}

Expand Down
4 changes: 2 additions & 2 deletions test/UnitTests/ProjectPropertiesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ TEST(ProjectPropertiesTest, ReplaceBugIDPlaceholder)
ASSERT_STREQ(L"http://tortoisesvn.tigris.org/issues/show_bug.cgi?id=123&bla=%25#anchor", url);

url = L"http://tortoisesvn.tigris.org/issues/show_bug.cgi?id=%BUGID%&bla=%25#anchor";
ProjectProperties::ReplaceBugIDPlaceholder(url, L"Äbf%def#g<hi j/kl+mn&o=,?");
ASSERT_STREQ(L"http://tortoisesvn.tigris.org/issues/show_bug.cgi?id=%C3%84bf%25def%23g%3Chi%20j%2Fkl%2Bmn%26o%3D,%3F&bla=%25#anchor", url);
ProjectProperties::ReplaceBugIDPlaceholder(url, L"Äbf%def#g<hi j/kl+mn&o=,?!*'();:@&=+$,/?%#[]");
ASSERT_STREQ(L"http://tortoisesvn.tigris.org/issues/show_bug.cgi?id=%C3%84bf%25def%23g%3Chi%20j%2Fkl%2Bmn%26o%3D%2C%3F%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%25%23%5B%5D&bla=%25#anchor", url);
}

0 comments on commit 8b74f96

Please sign in to comment.