From 6629a1f432b8b8bfec92c98ce3fa03fcf5ac79ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:37:30 +0000 Subject: [PATCH 1/3] 'main': Add a test for a $CDPATH bug. --- .../main/test-data/cdpath-abspath.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/cdpath-abspath.zsh diff --git a/highlighters/main/test-data/cdpath-abspath.zsh b/highlighters/main/test-data/cdpath-abspath.zsh new file mode 100644 index 0000000..1913e46 --- /dev/null +++ b/highlighters/main/test-data/cdpath-abspath.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +cdpath=( $PWD ) +mkdir foo foo/bar + +BUFFER="/foo" + +expected_region_highlight=( + '1 4 unknown-token "fixed in the next commit"' # x (/) +) From 08edf8db7f187d2ff5324516ffff099249d9f858 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:37:53 +0000 Subject: [PATCH 2/3] 'main': Fix the $CDPATH from the previous commit. --- highlighters/main/main-highlighter.zsh | 10 ++++++---- highlighters/main/test-data/cdpath-abspath.zsh | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e97b8b8..2f4c925 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -986,10 +986,12 @@ _zsh_highlight_main_highlighter_check_path() [[ -e $expanded_path ]] && return 0 # Search the path in CDPATH - local cdpath_dir - for cdpath_dir in $cdpath ; do - [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 - done + if [[ $expanded_path != /* ]]; then + local cdpath_dir + for cdpath_dir in $cdpath ; do + [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 + done + fi # If dirname($1) doesn't exist, neither does $1. [[ ! -d ${expanded_path:h} ]] && return 1 diff --git a/highlighters/main/test-data/cdpath-abspath.zsh b/highlighters/main/test-data/cdpath-abspath.zsh index 1913e46..64707b2 100644 --- a/highlighters/main/test-data/cdpath-abspath.zsh +++ b/highlighters/main/test-data/cdpath-abspath.zsh @@ -34,5 +34,5 @@ mkdir foo foo/bar BUFFER="/foo" expected_region_highlight=( - '1 4 unknown-token "fixed in the next commit"' # x (/) + '1 4 unknown-token' # x (/) ) From b1f36d9c5f45b879fbd2f64195167a60d9f3cb9e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:48:49 +0000 Subject: [PATCH 3/3] 'main': Add a comment. --- highlighters/main/main-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2f4c925..fbb149f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -988,6 +988,7 @@ _zsh_highlight_main_highlighter_check_path() # Search the path in CDPATH if [[ $expanded_path != /* ]]; then local cdpath_dir + # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. for cdpath_dir in $cdpath ; do [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 done