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

Re: [PATCH v4] Do not decode url protocol.

From
Jeff King <peff@peff.net>
Date
Jun 22, 2010, 22:46 UTC
Message-ID
<20100622224603.GA27423@coredump.intra.peff.net>
In-Reply-To
<4C211A39.2080207@obry.net>
On Tue, Jun 22, 2010 at 10:16:57PM +0200, Pascal Obry wrote:
Show 5 quoted lines
> When using the protocol git+ssh:// for example we do not want to
> decode the '+' as a space. The url decoding must take place only
> for the server name and parameters.
> 
> This fixes a regression introduced in 9d2e942.

Sorry, this is completely my fault. I obviously didn't test with git+ssh. I looked at adding a new test case, but I don't think there's an easy way. The only way to trigger it is by using "git+ssh" or "ssh+git"; any other protocol (real or fake) will be handled by a custom protocol handler and won't execute this broken code at all.

The patch looks reasonable (and I agree with all of Matthieu's comments thus far). With respect to the "what if there is no slash" issue discussed earlier, I prefer to be a bit defensive about possible inputs in library-ish functions like this. But:

Show 9 quoted lines
> +
> +       /* Skip protocol if present. */
> +       if (with_protocol) {
> +         first_slash = strchr(*query, '/');
> +
> +         while (q < first_slash)
> +               strbuf_addch(&out, *q++);
> +       }
> +

I think this actually works OK, given that "q < first_slash" will be false if first_slash is NULL, assuming NULL is all-bytes-zero or some low number (which is not guaranteed by the standard, but is a pretty practical assumption these days).

However, you could make things a little more efficient by handing the whole thing to strbuf at once:

  if (with_protocol) {
          const char *first_slash = strchr(q, '/');
          if (first_slash) {
                  strbuf_add(&out, q, first_slash - q);
                  q = first_slash;
          }
  }

which of course needs first_slash to be checked explicitly. Not that the efficiency probably matters in practice.

-Peff
Previous: Matthieu MoyNext: Junio C Hamano
Message 3 of 5 in “Do not decode url protocol.”
  1. Do not decode url protocol.Pascal Obry, Jun 22, 2010
  2. Matthieu MoyJun 22, 2010
  3. Jeff KingJun 22, 2010
  4. Junio C HamanoJun 23, 2010
  5. Jeff KingJun 23, 2010

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.