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