git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATH/RFC] parse-options: report invalid UTF-8 switches

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Feb 11, 2013, 17:21 UTC
Message-ID
<CABPQNSYtvXED_uj6m02N1-RWEdz3iMUUXUaNZquzy8GqQ2BnLw@mail.gmail.com>
In-Reply-To
<20130211171957.GG16402@sigill.intra.peff.net>
On Mon, Feb 11, 2013 at 6:19 PM, Jeff King <peff@peff.net> wrote:
Show 31 quoted lines
> On Mon, Feb 11, 2013 at 09:07:53AM -0800, Junio C Hamano wrote:
>
>> Erik Faye-Lund <kusmabite@gmail.com> writes:
>>
>> > However, since git only looks at one byte at the time for
>> > short-options, it ends up reporting a partial UTF-8 sequence
>> > in such cases, leading to corruption of the output.
>>
>> Isn't it a workable, easier and more robust alternative to punt and
>> use the entire ctx.argv[0] as unrecognized?
>
> Yes, but it regresses the usability:
>
>   [before]
>   $ git foobar -qrxs
>   unknown switch: x
>
>   [after]
>   $ git foobar -qrxs
>   unknown switch: -qrxs
>
> One is much more informative than the other, and you are punishing the
> common ascii case for the extremely uncommon case of utf-8. Maybe:
>
>   if (isascii(*ctx.opt))
>           error("unknown option `%c'", *ctx.opt);
>   else
>           error("unknown multi-byte short option in string: `%s'", ctx.argv[0]);
>
> which only kicks in in the uncommon case (and extends the error message
> to make it more clear why we are showing the whole string).

Yes. This is IMO a much better approach, and it doesn't involve trying to figure out what encoding the string is. Thanks!

Previous: Jeff KingNext: Junio C Hamano
Message 12 of 13 in “[PATH/RFC] parse-options: report invalid UTF-8 switches”
  1. Erik Faye-LundFeb 11, 2013
  2. Matthieu MoyFeb 11, 2013
  3. Erik Faye-LundFeb 11, 2013
  4. Matthieu MoyFeb 11, 2013
  5. Erik Faye-LundFeb 11, 2013
  6. Torsten BögershausenFeb 11, 2013
  7. Erik Faye-LundFeb 11, 2013
  8. Torsten BögershausenFeb 11, 2013
  9. Junio C HamanoFeb 11, 2013
  10. Erik Faye-LundFeb 11, 2013
  11. Jeff KingFeb 11, 2013
  12. Erik Faye-LundFeb 11, 2013
  13. Junio C HamanoFeb 11, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.