From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056797; b=rQKtLALDeiO/lZe8PEtIMjeXaUTmnnVuvJHezo2mVCYEgnYDGlpR7DtKnMiXgzLvx6ed ABIkLxzyq22hPCbtvei4ZlBqdcg3RuUEt0BA4fnZZvBV3E7ARBwgFImH/K2ONAJqfgZY6 6ymCGxz7fn7M9N0O7nyVLdXg2Y2IiayP7COLCb1TqeZ1bGknRoA/sh706WBWJcrrsL5v9 SnN3EP9K4C9rlHCK8JMjurWfNFfo98fgwu/RUHMSMnCAZ93RLn1s5jZnKVa42tDPWrLre tK0taggYcDm3Oa/hd2o2VUlbcH//llrRbo9JoUE0BN1/nL+UM9HcriMchT4y7Hq1fDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056797; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-ID:Date: MIME-Version:User-Agent:From:Reply-To:Subject:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=; b=PcK0SBexo0GmUZFSgyfODhPIJcXMIVz9GPNVThmYFki6fydq7XknqjJPZBZvviZGo1Xk 8Mh28d6y5+fA82jIyfbjjQgwqlisZdOhbJxIQQXEhMJzDzmj/j8KLadyz5/dYvq3AhLE8 j49aD6zpgFTH59t3CdQHGxFMbOmKP3LBSuavqqzbMIYDjrVPiYQwoNKScKGCmYH7qZCPi 28A7rugJQX2bmN+AcAgyi9/dydLT8C9O1w0sUx9OGDzd5f+zSvv2lyvfAAvKWY6mGii8g WRjp2Pnk6wegpQi6QM1DZFDP2+pVDKh4L4O8U55d1zjEZ9IN1pIGTHR+d0nzRJnuCLg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ltxMRHQx; arc=none smtp.remote-ip=209.85.221.42 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93B60606A31C for ; Mon, 30 Nov 2026 16:39:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93B60606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ltxMRHQx Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-491f34b4e0fso4776831f8f.2 for ; Mon, 30 Nov 2026 08:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796056796; x=1796661596; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:reply-to:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=; b=ltxMRHQxvvUOeN7dQBggZyjG7oJvTJVXJKwFjdqrlAHpz92EyZvebsfLSyaCPBb3fK VrcZ9O9c6Z7ezi/EvmYuwqbUEH8sreJ8wXrmRkacPvgWGHNbb/1N97seusLnypwKSSWd k67ORsZU10bULkmuHsOpoVPZ2loMBHj6fNG17SYeWN6NY7BDdn+CIpFljwDzlqZ5GNpD 08rPmvazfP0Y4vP1All7IiWIaUkhUVKDYBb3nwFBAYQoWcPh42CL5kYBmmm6a+ISxoBf F27NA3bb9N/t9x7Dyq4+Cqm0QiV+6sr+RaSo1W7bBd6jRCLMKkyrP1AqdG+rNeOg62xu 9qdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796056796; x=1796661596; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:reply-to:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=voU8exZkDufjVOQSwdMGclep6MnLVwP2t9t+7BBAQJ4=; b=iVklrNRRB/mLAIZlxcdidF7fa168ufery8/KFGQqnGAwoM5DWD0C7VkRFHMLFOlg/8 b/aAAae1TH5IPREnmc4N9V/ZTSU9Af6onH15Dbpu/g2WKnbso16sGTh50CrA4z8vl9Py 0DgLl1Ye4QSnRo8ZSYHzm+ASCIj4aFHs1osCT5/NWzhNsPWtrmXlXpwIIHo+9m5wkaPr +twJckBRjfZnNF+99pmWN20Q1oZeUuIpeNfJTlDgzaFLbMEkzzBUDU2XLFE//JsnDIDy bZNWA8ls8nnWrzp2qOONLZFqtpe1T5DSRc+CRU7JJALQ8a3u7Xeijt8emHUH5aSHOJDG /zvQ== X-Gm-Message-State: APuU4Z9ic7ItD02N8f9IEFTNHTXiTjFQ65InF0iI48WgtFIo3iheIO/K ju8GKimK+GprOWB3qxZgcoX6IyjFHry4rZM6kr+Oy3IUL2M3FFaZt96j X-Gm-Gg: AZFdTZfbATXEuM/BEsh9U7m7x5IaWsdyto9Y9VvzbKpsITTBZaKNflYFIZdcpHovzRF 9tMwTdyrIMbHdSFguwmdKrijzNgNDZhkD0mgn66IdyNFUjJ7P8xGOtgMaI5sh8m9hJZp+ikCE7o X0FgZMDVL6LTO829awGMFPEQi+tkaV621q9Xjvltaxx3vTZY98Dcvb/TTlUUXQzkHGCq8Mmkpao 6gSPd2GJ7FcofaYPhRszhDK7gbz3INclaZC2MFJq/FfNqXbd2T4Bcgm7Ea+mmgVtqcpquS8lp4F birEAVQ184A4+fsonBkzctMgdLnv11w2y2DqlHqzPFdeJtxbUlWTlpceaCQ6LvMZ+Ld+lsI8zAT DiiiTWVs6s6Mo5xweH0eb+0THkVlL623y1Hcz4bT8y7xT3jjyUhwbJg/ldqKdCPLzEUpWGLzo/T b/HB3Yhq74YnSvXS8EHV4yIe7jDusNqOEeEtHKCr2ZejPsk/G7lkRcmoE6L7TVZEHo+LGUekg03 3ry0eSN/MfFKXSwfTvfQeElboNY5KhKR55aaH+gKKcVhcQuQzx/TIpmLzT26F9uWv4nObd7qMCk TxoIUfRips4rdrgDhmV7utIOEnChtWR8kIqa7IoArNwIdCIiNUWDa6e6A9sHAgD/ukAXy2HUF5/ QepDC9Qii X-Received: by 2002:a05:6000:2512:b0:4b7:75cf:37fc with SMTP id ffacd0b85a97d-4b775cf386amr39376744f8f.52.1796056795639; Mon, 30 Nov 2026 08:39:55 -0800 (PST) Received: from ?IPV6:2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f? ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a67f204sm82022176f8f.21.2026.11.30.08.39.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 08:39:55 -0800 (PST) Message-ID: <01526f4d-b40e-4288-aa22-441c3e6e68e2@gmail.com> Date: Mon, 30 Nov 2026 16:39:54 +0000 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Phillip Wood Reply-To: phillip.wood@dunelm.org.uk Subject: Re: [RFC PATCH] quote: make sq_quote_buf_pretty() prettier To: Junio C Hamano Cc: git@vger.kernel.org, Ben Knoble , Harald Nordgren , MD Nahid Hasan Sagor References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 27/11/2026 20:31, Junio C Hamano wrote: > Phillip Wood writes: > >> +static bool needs_sq_quote(char c, unsigned brace) >> +{ >> + if (isalnum(c) || (unsigned char)c > 0x7f) >> + return false; >> + >> + switch (c) { >> + case ',': >> + return brace > 0; /* Prevent brace expansion */ > > Web search tells me that bash, zsh, and ksh93 expands sequence > expressions such as "{1..5}" or "{a..z}" without any comma in the pair > of braces. Because '.' returns false unconditionally here and no other > check triggers quoting for "..", sq_quote_buf_pretty() leaves "{1..5}" > unquoted, which expands to five arguments if pasted into those shells. Oh, thanks for pointing that out. I think it should be fairly easy to detect '..' when brace != 0 >> + /* '~' is only special if it is the first character */ >> + if (*p == '~') { >> + quote_it = true; >> + p++; >> } > > As noticed by Nahid already, this loses the leading '~'. Also, do we > want to do something to this corner case? > > $ echo P=A:~/B:C > P=A:/home/gitster/B:C > > i.e., bash and friends seem to expand ~ that is not at the beginning of > value when the whole thing looks like a variable assignment. Without > "P=" at front, this does not seem to expand. Thanks, having read the manuals bash, zsh and ksh all have slightly different behaviors (and the zsh behavior depends on which options are set). Quoting strings that start with '~', or contain '=~' or ':~', is sufficient to prevent tilde expansion while avoiding quoting 'HEAD~1'. zsh has an EXTENDED_GLOB option where '~' matches everything that would match that does not. Luckily, it seems to need another special character in one of the patterns to trigger it so we don't need to quote "HEAD~1". The EXTENDED_GLOB option also treats '^' specially, so to be safe we should be quoting anything containing '^' which we don't at the moment. That's a shame it means we need to quote "HEAD^2". EXTENDED_GLOB is not enabled by default, but I think it is worth making our output safe when it is enabled. By default, zsh also expands "=cmd" to the absolute path of "cmd" in the same places as '~' would be subject to tilde expansion. On a related note our treatment of assignments is a bit strange - if the right hand side needs quoting then we quote the whole thing which disables the assignment, but we don't quote it otherwise. When sq_quote_buf_pretty() was introduced the aim seems to have been to be able to copy and paste tracing output to rerun the command being traced, which would imply we don't want to disable assignments when the right hand side needs to be quoted. I'll try and re-roll later this week Thanks Phillip