diff src/process.c @ 5883:d93195c2c906

Escape quotation marks when printing values interactively, #'getenv src/ChangeLog addition: 2015-04-01 Aidan Kehoe <kehoea@parhasard.net> * process.c (Fgetenv): When interactively showing a variable's value, use %S in the format string so quotation marks are escaped correctly.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 03 Apr 2015 00:15:18 +0100
parents a216b3c2b09e
children
line wrap: on
line diff
--- a/src/process.c	Wed Apr 01 14:28:20 2015 +0100
+++ b/src/process.c	Fri Apr 03 00:15:18 2015 +0100
@@ -2431,11 +2431,11 @@
 {
   Ibyte *value = NULL;
   Bytecount valuelen;
-  Lisp_Object v = Qnil;
-  struct gcpro gcpro1;
+  Lisp_Object v = Qnil, formatted = Qnil;
+  struct gcpro gcpro1, gcpro2;
 
   CHECK_STRING (var);
-  GCPRO1 (v);
+  GCPRO2 (v, formatted);
   if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
 		       &value, &valuelen))
     v = make_string (value, valuelen);
@@ -2444,9 +2444,11 @@
       if (NILP (v))
 	message ("%s not defined in environment", XSTRING_DATA (var));
       else
-	/* #### Should use Fprin1_to_string or Fprin1 to handle string
-           containing quotes correctly.  */
-	message ("\"%s\"", value);
+        {
+          /* Backslash any quotation marks. */
+          formatted = Fprin1_to_string (v, Qnil);
+          message_internal (NULL, formatted, 0, -1);
+        }
     }
   RETURN_UNGCPRO (v);
 }