Skip to content

Commit 0a78b71

Browse files
Fix forgotten update of the number of characters left in dumping UTF-8
We forgot to update the counter variable. This fixes #54. Signed-off-by: Thiago Macieira <[email protected]>
1 parent eed8aa4 commit 0a78b71

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/cborpretty.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static int utf8EscapedDump(FILE *out, const char *buffer, size_t n)
190190

191191
if (n < charsNeeded - 1)
192192
return CborErrorInvalidUtf8TextString;
193+
n -= charsNeeded - 1;
193194

194195
/* first continuation character */
195196
uint8_t b = (uint8_t)*buffer++;

tests/parser/tst_parser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ void addStringsData()
333333
QTest::newRow("textstring256") << raw("\x79\1\0") + QByteArray(256, '3')
334334
<< '"' + QString(256, '3') + '"';
335335

336+
// some strings with UTF-8 content
337+
// we had a bug in the pretty dumper - see issue #54
338+
QTest::newRow("textstringutf8-2char") << raw("\x62\xc2\xa0") << "\"\\u00A0\"";
339+
QTest::newRow("textstringutf8-2char2") << raw("\x64\xc2\xa0\xc2\xa9") << "\"\\u00A0\\u00A9\"";
340+
QTest::newRow("textstringutf8-3char") << raw("\x63\xe2\x88\x80") << "\"\\u2200\"";
341+
QTest::newRow("textstringutf8-4char") << raw("\x64\xf0\x90\x88\x83") << "\"\\uD800\\uDE03\"";
342+
336343
// strings with overlong length
337344
QTest::newRow("emptybytestring*1") << raw("\x58\x00") << "h''";
338345
QTest::newRow("emptytextstring*1") << raw("\x78\x00") << "\"\"";

0 commit comments

Comments
 (0)