SwiftCBOR icon indicating copy to clipboard operation
SwiftCBOR copied to clipboard

CBOR Decode error with special characters

Open MathieuChe opened this issue 2 years ago • 1 comments

Hey guys,

I have an issue as a french developer. I use special characters such as "é", "è", "ë" for example.
And other users from other countries write in other language which need to use special characters.

Unfortunately, CBOR.decode() catch an error, that we cannot parse this data.
 242676622-6b9a72be-6d09-40e0-b768-4c1fad8cb8ae

This method decode() try to return decodeItem()
 242627870-0db6783c-f40a-404a-a95c-13675891fc13

As you can see below, it tries to decodeUtf8 from Util class,
 242627670-0f9404dd-2727-457e-b112-9f367811138c

decodingResult returns an error because decoder(UTF8) can't decode(&generator)
 242627545-46cfd98d-fe30-4d58-8310-2d6cc01bbb4b

It may be a problem caused by UTF8 encoding type ?
 How could we fix this and help people who might have the same issue ?
 Thank you guys.

MathieuChe avatar Jun 01 '23 17:06 MathieuChe

Hey @MathieuChe I tried writing a test that roundtrips (encodes and then decodes) a string that has an é character in it and the test seemed to work fine. This is what I did:

func testAccentedCharacter() {
    let accented = try! CodableCBOREncoder().encode("Touché")
    let accentedDecoded = try! CodableCBORDecoder().decode(String.self, from: french)
    XCTAssertEqual(accentedDecoded, "Touché")
}

Please could you provide some code that some input, e.g. an example String, that is failing for you, and then I can debug things further. Thanks!

hamchapman avatar Jun 05 '23 16:06 hamchapman