Kim van der Riet created PROTON-2249:
----------------------------------------

             Summary: [Proton-c] AMQP char type does not always print correctly 
from pn_inspect()
                 Key: PROTON-2249
                 URL: https://issues.apache.org/jira/browse/PROTON-2249
             Project: Qpid Proton
          Issue Type: Bug
            Reporter: Kim van der Riet


The *{{pn_inspect()}}* method returns a string representation of the inspected 
AMQP type.

While testing an array of type char in which the first char had value 0x0, it 
was observed that this method is not correctly printing the array, but is being 
truncated:
{noformat}
"@PN_CHAR["
{noformat}
and prevents effective checking of the array contents in the test.

The formatting of simple AMQP types is set in the *{{pni_inspect_atom()}}* 
method. The following suggested change fixes this issue and prefixes each char 
with 'U' to indicate it is UTF-32:
{noformat}
diff --git a/c/src/core/codec.c b/c/src/core/codec.c
index b50f286b..1f9185f7 100644
--- a/c/src/core/codec.c
+++ b/c/src/core/codec.c
@@ -129,7 +129,8 @@ int pni_inspect_atom(pn_atom_t *atom, pn_string_t *str)
 case PN_INT:
 return pn_string_addf(str, "%" PRIi32, atom->u.as_int);
 case PN_CHAR:
- return pn_string_addf(str, "%c", atom->u.as_char);
+ if (isprint(atom->u.as_char)) return pn_string_addf(str, "U'%c'", 
atom->u.as_char);
+ return pn_string_addf(str, "U'\\x%" PRIx32 "'", atom->u.as_char);
 case PN_ULONG:
 return pn_string_addf(str, "%" PRIu64, atom->u.as_ulong);
 case PN_LONG:
{noformat}
and the array prints as:
{noformat}
"@PN_CHAR[U'\x0', U'5', U'a', U'Z', U'\x7f']"
{noformat}
The following are improved:
 * Each char is surrounded by single quotes {{'\''}}
 * Each char is prefixed by 'U' to indicate it is UTF-32 (see 
[https://en.cppreference.com/w/cpp/language/character_literal)|https://en.cppreference.com/w/cpp/language/character_literal]
 * Printable chars print as the char itself, non-printable chars print as the 
hex ordinal value.

Thoughts?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to