 Issue 6012307226230784:
  Issue #1234 - std::wstring version of UnescapeUrl  (Closed)
    
  
    Issue 6012307226230784:
  Issue #1234 - std::wstring version of UnescapeUrl  (Closed) 
  | 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, | 
| + * 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. | 
| + */ | 
| + std::unique_ptr<wchar_t> result(new wchar_t[result_length]); // can throw bad_alloc | 
| 
sergei
2014/08/05 12:53:04
It's better to use `std::unique_ptr<wchar_t[]>`.
 
Eric
2014/08/05 13:09:10
Yep. Missed that one.
 | 
| + /* | 
| + * 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); | 
| 
Oleksandr
2014/08/05 12:20:58
Nit: no space after &
 
Eric
2014/08/05 17:53:01
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. | 
| + * Because there's no error handling, however, this masks failures in UrlUnescape. | 
| + */ | 
| + } | 
| + catch(...) | 
| + { | 
| 
Oleksandr
2014/08/05 12:20:58
I personally am very cautious with empty catch-all
 
sergei
2014/08/05 12:53:04
+1 here.
Each time such all exception eating const
 
Eric
2014/08/05 13:09:10
Look, I agree with both of you. I do not like blan
 | 
| + // no modification if exception | 
| + } | 
| +} | 
| void CPluginClientBase::LogPluginError(DWORD errorCode, int errorId, int errorSubid, const CString& description, bool isAsync, DWORD dwProcessId, DWORD dwThreadId) | 
| { |