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 Aug. 5, 2014, 5:51 p.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,38 @@
return url;
}
+void UnescapeUrl(std::wstring& url)
+{
+ /*
+ * When the code can tolerate exceptions better,
Felix Dahlke 2014/08/15 15:32:29 I think this comment should go into the catch bloc
Eric 2014/09/29 11:50:07 OK. Since I've written this code, I've come to th
+ * there's no reason to keep this try-catch statement in place.
+ */
+ try
+ {
+ DWORD result_length = INTERNET_MAX_URL_LENGTH;
+ /*
+ * The buffer length is greater than 2 Kb, so we keep it off the stack and allocate it.
Eric 2014/09/29 11:50:07 Done.
+ */
+ std::unique_ptr<wchar_t[]> result(new wchar_t[result_length]); // can throw bad_alloc
+ /*
+ * Casting away const here is harmless because we're not using the in-place modification mode of UrlUnescape
Felix Dahlke 2014/08/15 15:32:29 This is pretty obvious from the documentation of U
Felix Dahlke 2014/09/30 09:10:28 We have the exact same problem in several cases -
Eric 2014/09/30 15:22:21 UrlUnescape is worse than the usual Windows API, b
Felix Dahlke 2014/09/30 16:08:16 Yeah, that's true. Still - at the end of the day t
sergei 2014/10/06 09:08:54 I would say that this comment could be here or may
+ */
+ HRESULT hr = UrlUnescapeW(const_cast<wchar_t *>(url.c_str()), result.get(), &result_length, 0);
Felix Dahlke 2014/08/15 15:32:29 No space between wchar_t and *.
Eric 2014/09/29 11:50:07 Done.
+ if (hr == S_OK)
+ {
+ url = std::wstring(result.get(), result_length);
+ }
+ /*
+ * If the call to UrlUnescape fails, we don't alter the string.
+ * This matches the behavior of the previous version of this function.
Felix Dahlke 2014/08/15 15:32:29 How about changing "the previous version" to "the
Eric 2014/09/29 11:50:07 I'm moving this comment to the function header, si
Felix Dahlke 2014/09/30 09:10:28 Yeah, good point. I think the comment remaining he
Eric 2014/09/30 15:22:21 I'll fix the comment again. What's not obvious i
Felix Dahlke 2014/09/30 16:08:16 Fair enough.
+ * Because there's no error handling, however, this masks failures in UrlUnescape.
+ */
+ }
+ catch(...)
+ {
+ // no modification if 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