Subject: Re: (split-string-and-unquote (combine-and-quote-strings STRINGS)) fails on trivial case

From: Stefan Monnier <[email-masked]>
Date: Mon, 07 Apr 2008 12:23:25 -0400

>> The documentation strings for both split-string-and-unquote and
>> combine-and-quote-strings state that they attempt to achieve this
>> property:
>> 
>> (split-string-and-unquote (combine-and-quote-strings strs)) == strs
>> 
>> Here is a trivial case that they fail on; the following sexp wrongly
>> evaluates to nil:
>> 
>> (let ((l '("a b" "c")))
>> (equal l
>> (split-string-and-unquote (combine-and-quote-strings l))))

> I think this is a docstring mistake.

I disagree.  This is a bug in the code.  I believe the patch below fixes it.

        Stefan

--- subr.el.~1.588.~	2008-04-07 10:23:51.000000000 -0400
+++ subr.el	2008-04-07 12:21:23.000000000 -0400
@@ -2987,10 +2987,11 @@
 This tries to quote the strings to avoid ambiguity such that
   (split-string-and-unquote (combine-and-quote-strings strs)) == strs
 Only some SEPARATORs will work properly."
-  (let ((sep (or separator " ")))
+  (let* ((sep (or separator " "))
+         (re (concat "[\\\"]" "\\|" (regexp-quote sep))))
     (mapconcat
      (lambda (str)
-       (if (string-match "[\\\"]" str)
+       (if (string-match re str)
 	   (concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"")
 	 str))
      strings sep)))