Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginClientBase.cpp

Issue 6012307226230784: Issue #1234 - std::wstring version of UnescapeUrl (Closed)
Patch Set: Created Sept. 29, 2014, 11:48 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginClientBase.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginClientBase.cpp
===================================================================
--- a/src/plugin/PluginClientBase.cpp
+++ b/src/plugin/PluginClientBase.cpp
@@ -66,6 +66,36 @@
return url;
}
+void UnescapeUrl(std::wstring& url)
+{
+ try
+ {
+ DWORD result_length = INTERNET_MAX_URL_LENGTH;
+ std::unique_ptr<wchar_t[]> result(new wchar_t[result_length]);
+ /*
+ * Casting away const here is harmless because we're not using the in-place modification mode of UrlUnescape
+ */
+ HRESULT hr = UrlUnescapeW(const_cast<wchar_t*>(url.c_str()), result.get(), &result_length, 0);
+ if (hr == S_OK)
+ {
+ url = std::wstring(result.get(), result_length);
+ }
+ /*
+ * If the call to UrlUnescape fails, we don't alter the string.
+ */
+ }
+ catch(std::bad_alloc e)
+ {
+ /*
+ * When the code has a systematic way of handling bad_alloc, we'll rethrow (probably).
+ * Until then, we mask the exception and make no modification.
+ */
+ }
+ catch(...)
+ {
+ // no modification if any other exception
+ }
+}
void CPluginClientBase::LogPluginError(DWORD errorCode, int errorId, int errorSubid, const CString& description, bool isAsync, DWORD dwProcessId, DWORD dwThreadId)
{
« no previous file with comments | « src/plugin/PluginClientBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld