XML Output: libxo - provide single API to output TXT, XML, JSON and HTML

Phil Shafer phil at juniper.net
Mon Aug 4 14:50:00 UTC 2014


Poul-Henning Kamp writes:
>First of, this is not just ENOMEM, this is also invalid UTF-8 strings,
>NULL pointers and much more bogosity.

Yup, there are 26 failure cases at present, ranging from missing
close braces in format strings to unbalanced open/close calls.

>>Seeing broken output is better than limping
>>along with output that looks right but isn't.
>The output should preferably be explicitly broken, so that nobody 
>downstream mistakenly takes it and runs with it.

I think we're in agreement, but there is the question of what
constitutes sufficient problems to trigger abort.  I'm coding the
UTF-8 support now and that's a perfect example.  If the output
character set (the user's LANG setting) doesn't support a character
of output (u+10d6), does that constitute a complete failure?  I'll
assumably give flags to tailor the behavior, but by default, I'd
be upset if character conversion issues like this turned into
complete failure.  But a format string with an invalid UTF-8 sequence
would be more severe.

FWIW, the UTF-8 strategy for libox is this:
- all format strings are UTF-8
- argument strings (%s) are UTF-8
- "%ls" handles wide characters
- "%hs" will handle locale-based strings
- XML, JSON, and HTML will be UTF-8 output
- text will be locale-based

The painful part is that I've been using vsnprintf as the plumbing
for formatting strings, but it doesn't handle field widths for UTF-8
data correctly, so I'll need to start doing that by handle myself.

Thanks,
 Phil


More information about the freebsd-arch mailing list