From 74949c2d9198dc8be9d1f3c6bc74c16a35098218 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Dec 2016 09:07:37 +0000 Subject: [PATCH 1/3] driver: Don't undefine aliases that begin with a '+', to workaround an upstream bug. Fixes #392. --- zsh-syntax-highlighting.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index fff47d1..52d35f2 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -28,8 +28,12 @@ # ------------------------------------------------------------------------------------------------- # First of all, ensure predictable parsing. -zsh_highlight__aliases=`builtin alias -L` -builtin unalias -m '*' +zsh_highlight__aliases=`builtin alias -Lm '[^+]*'` +# In zsh <= 5.2, `alias -L` emits aliases that begin with a plus sign ('alias -- +foo=42') +# them without a '--' guard, so they don't round trip. +# +# Hence, we exclude them from unaliasing: +builtin unalias -m '[^+]*' # Set $0 to the expected value, regardless of functionargzero. 0=${(%):-%N} From 67be62107be0882f7ca09a191ffbafcb1ee9097a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 2 Dec 2016 09:50:55 +0000 Subject: [PATCH 2/3] tests: Move some code in preparation for next commit. No functional change. --- tests/test-highlighting.zsh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 1d169d6..6f7fa96 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -47,6 +47,19 @@ exit 2 } +# Set up results_filter +local results_filter +if [[ $QUIET == y ]]; then + if type -w perl >/dev/null; then + results_filter=${0:A:h}/tap-filter + else + echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2 + fi +else + results_filter=cat +fi +[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } + # Load the main script. . ${0:h:h}/zsh-syntax-highlighting.zsh @@ -157,19 +170,6 @@ run_test() { } } -# Set up results_filter -local results_filter -if [[ $QUIET == y ]]; then - if type -w perl >/dev/null; then - results_filter=${0:A:h}/tap-filter - else - echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2 - fi -else - results_filter=cat -fi -[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } - # Process each test data file in test data directory. integer something_failed=0 ZSH_HIGHLIGHT_STYLES=() From 5efd062a4d2c8fe37864a0108059a33e37656682 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 2 Dec 2016 09:35:29 +0000 Subject: [PATCH 3/3] tests: Add a regression test for issue #392 (aliases beginning with a '+' are lost). --- tests/test-highlighting.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6f7fa96..94c4152 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -61,7 +61,19 @@ fi [[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } # Load the main script. +# While here, test that it doesn't eat aliases. +print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "# global (driver) tests" +print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "1..1" +alias -- +plus=plus +alias -- _other=other +original_alias_dash_L_output="$(alias -L)" . ${0:h:h}/zsh-syntax-highlighting.zsh +if [[ $original_alias_dash_L_output == $(alias -L) ]]; then + print -r -- "ok 1 # 'alias -- +foo=bar' is preserved" +else + print -r -- "not ok 1 # 'alias -- +foo=bar' is preserved" + exit 1 +fi > >($results_filter | ${0:A:h}/tap-colorizer.zsh) # Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style _zsh_highlight_add_highlight()