e4b47d
From 53297b1441539efdc44fc9c8f4f19fb6ba8290c9 Mon Sep 17 00:00:00 2001
e4b47d
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
e4b47d
Date: Thu, 21 Nov 2013 12:03:32 +0100
e4b47d
Subject: [PATCH] Fix setting undefined variable in CSH
e4b47d
MIME-Version: 1.0
e4b47d
Content-Type: text/plain; charset=UTF-8
e4b47d
Content-Transfer-Encoding: 8bit
e4b47d
e4b47d
<https://rt.cpan.org/Public/Bug/Display.html?id=85667>
e4b47d
e4b47d
Signed-off-by: Petr Písař <ppisar@redhat.com>
e4b47d
---
e4b47d
 lib/local/lib.pm | 19 ++++++++++++++++++-
e4b47d
 1 file changed, 18 insertions(+), 1 deletion(-)
e4b47d
e4b47d
diff --git a/lib/local/lib.pm b/lib/local/lib.pm
e4b47d
index 289e13b..d4f8e2a 100644
e4b47d
--- a/lib/local/lib.pm
e4b47d
+++ b/lib/local/lib.pm
e4b47d
@@ -343,7 +343,24 @@ sub build_bourne_env_declaration {
e4b47d
 sub build_csh_env_declaration {
e4b47d
   my $class = shift;
e4b47d
   my($name, $value) = @_;
e4b47d
-  return defined($value) ? qq{setenv ${name} "${value}";\n} : qq{unsetenv ${name};\n};
e4b47d
+  if (defined($value)) {
e4b47d
+    if ($value =~ /(.*)(\A|\Q$Config{path_sep}\E)(\$)(.+?)(\z|\Q$Config{path_sep}\E)(.*)/) {
e4b47d
+      # If a variable reference exists in the value, we have to delimit it and
e4b47d
+      # dereference it only if it is defined.
e4b47d
+      return
e4b47d
+        qq{test 1 == \$\{?$4\} && } .
e4b47d
+        qq{setenv ${name} "${1}${2}${3}\{${4}\}${5}${6}"} .
e4b47d
+        qq{ || } .
e4b47d
+        qq{setenv ${name} "${1}} .
e4b47d
+          (($2 ne '' and $5 ne '') ?  qq{${2}} : '') .
e4b47d
+          qq{${6}"} .
e4b47d
+        qq{;\n};
e4b47d
+    } else {
e4b47d
+        return qq{setenv ${name} "${value}";\n};
e4b47d
+    }
e4b47d
+  } else {
e4b47d
+    return qq{unsetenv ${name};\n};
e4b47d
+  }
e4b47d
 }
e4b47d
 
e4b47d
 sub build_win32_env_declaration {
e4b47d
-- 
e4b47d
1.8.3.1
e4b47d