From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25259 invoked by alias); 15 Feb 2015 22:57:48 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34551 Received: (qmail 17679 invoked from network); 15 Feb 2015 22:57:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=LrklEcZZ c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=0HtSIViG9nkA:10 a=Y6CY-yZ3KOw7X0-z90EA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150215145716.ZM11860@torch.brasslantern.com> Date: Sun, 15 Feb 2015 14:57:16 -0800 In-reply-to: <54E0FF31.5040609@pobox.com> Comments: In reply to Andrew Janke "[BUG] cdpath=(.) breaks cd from / on Cygwin" (Feb 15, 3:18pm) References: <54E0FF31.5040609@pobox.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Andrew Janke , zsh-workers@zsh.org Subject: Re: [BUG] cdpath=(.) breaks cd from / on Cygwin MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 15, 3:18pm, Andrew Janke wrote: } } In Src/builtin.c, function cd_try_chdir(), lines 1080-1093, there's some } special case handling for Cygwin and the prefix '/'. But when the prefix } is '.', it goes down a different code path. It constructs the path } starting from pwd (which is '/' in this case), and then goes through the } path normalization which elides '.' segments. But it doesn't have a } special case check for Cygwin to check for leading '/' again. And I } think the elision of the first '.' segment will result in a computed } path starting with '//' but not further escaped. That's a pretty close analysis. The real problem is that when pwd is "/", cd_try_chdir() unnecessarily inserts yet another "/" into the path before appending a cdpath segment (the "pfix"). So the path has already become "//./" before normalization even begins. This is a waste of effort when pwd is "/" on any platform. I'm not sure why we bother compiling different branches for cygwin and otherwise in cd_try_chdir(). Doesn't appear the cygwin variation would be wrong anywhere else. But I won't mess with that here. Try this patch: diff --git a/Src/builtin.c b/Src/builtin.c index c4e4b94..614b17d 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1093,9 +1093,11 @@ cd_try_chdir(char *pfix, char *dest, int hard) } else { int pfl = strlen(pfix); dlen = strlen(pwd); - + if (dlen == 1 && *pwd == '/') + dlen = 0; buf = zalloc(dlen + pfl + strlen(dest) + 3); - strcpy(buf, pwd); + if (dlen) + strcpy(buf, pwd); buf[dlen] = '/'; strcpy(buf + dlen + 1, pfix); buf[dlen + 1 + pfl] = '/';