Azure / Azure/azure-sdk-for-cpp
UTF-8 vs current code page inconsistency
- Dominant language
- C++
- Stars
- 205
- Forks
- 172
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 37
Description
**Describe the bug**
When I download a file using `BlockBlobClient::DownloadTo`, I need to convert `CString` to `std::string` using `CP_UTF8` in `CW2A` call which is expected. However If want to upload a file using `UploadFrom` then the filename must not be in UTF-8 but in current code page (no page specified in `CW2A`.
***Exception or Stack Trace***
When I upload a file, I get an error during the call so convert back the filename to a wide filename if it contains accentuated characters.
**To Reproduce**
Call those functions with accentuated filename coming from `CString` object.
***Code Snippet***
```
void ReadBlob(const CString &fileName, const CString &blobName)
{
const std::string blobNameUtf8(CW2A(blobName.GetString(), CP_UTF8));
const std::string filename(CW2A(fileName.GetString(), CP_UTF8)); // *** Must have CP_UTF8 here
BlockBlobClient blockBlob = m_ContainerClient->GetBlockBlobClient(blobNameUtf8);
blockBlob.DownloadTo(filename);
}
void WriteBlob(const CString &fileName, const CString &blobName)
{
const std::string blobNameUtf8(CW2A(blobName.GetString(), CP_UTF8));
const std::string filename(CW2A(fileName.GetString())); // *** Must NOT have CP_UTF8 here
BlockBlobClient blockBlob = m_ContainerClient->GetBlockBlobClient(blobNameUtf8);
blockBlob.DeleteIfExists();
blockBlob.UploadFrom(filename);
}
```
**Expected behavior**
Consistent use of UTF-8 in API.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Setup (please complete the following information):**
- OS: Windows 11
- IDE : Visual Studio 2022
- Version of the Library used 1.12.0 and 1.15.0
**Additional context**
With incorrect encoding, operation on file fails when filename contains accentuated characters.
**Information Checklist**
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x] Bug Description Added
- [x] Repro Steps Added
- [x] Setup information Added
Contributor guide
Assessment
This issue has not been assessed yet.