Skip to content

UTF-8 vs current code page inconsistency #6561

Open
@PhilippeM1970

Description

@PhilippeM1970

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

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Assignees

No one assigned

    Labels

    Azure.CorebugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions