Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Aug 2014 10:48:58 -0400
From:      Phil Shafer <phil@juniper.net>
To:        Poul-Henning Kamp <phk@phk.freebsd.dk>
Cc:        arch@freebsd.org, John-Mark Gurney <jmg@funkthat.com>, marcel@freebsd.org, "Simon J. Gerraty" <sjg@juniper.net>
Subject:   Re: XML Output: libxo - provide single API to output TXT, XML, JSON and HTML
Message-ID:  <201408041449.s74Emwk0019816@idle.juniper.net>
In-Reply-To: <63132.1406924887@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408041449.s74Emwk0019816>