Subject: bug#105 closed by Stefan Monnier <[email-masked]> (Re: (split-string-and-unquote (combine-and-quote-strings STRINGS)) fails on trivial case)

From: [email-masked] (Emacs bug Tracking System)

This is an automatic notification regarding your bug report
which was filed against the emacs package:

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

It has been closed by Stefan Monnier <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Stefan Monnier <[email-masked]> by
replying to this email.

-- 
105: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=105
Emacs Bug Tracking System
Contact [email-masked] with problems
>From [email-masked] Mon Apr  7 09:23:34 2008
From: Stefan Monnier <[email-masked]>
To: [email-masked]
Subject: Re: (split-string-and-unquote (combine-and-quote-strings STRINGS)) fails on trivial case
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)))

>From [email-masked] Mon Mar 31 19:56:39 2008
Resent-Message-ID: <[email-masked]>
Resent-To: [email-masked]
Resent-From: Stefan Monnier <[email-masked]>
Resent-Date: Mon, 31 Mar 2008 22:56:28 -0400
To: [email-masked]
From: Joe Wells <[email-masked]>
Date: Tue, 01 Apr 2008 02:17:23 +0100
Subject: (split-string-and-unquote (combine-and-quote-strings STRINGS))
	fails on trivial case
Sender: bug-gnu-emacs-bounces+monnier=[email-masked]

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 hope this problem report is helpful.

Joe

======================================================================
In GNU Emacs 22.2.1 (i686-pc-linux-gnu, GTK+ Version 2.8.20)
 of 2008-04-01 on artemis
Windowing system distributor `The X.Org Foundation', version 11.0.70000000
configured using `configure  '--prefix=/home/jbw/local4' '--enable-debug' '--disable-nls' '--with-x-toolkit=gtk' 'CFLAGS=-O0 -g3 -ggdb -fno-crossjumping -DGLYPH_DEBUG=1''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: jbw
  value of $LANG: nil
  locale-coding-system: utf-8
  default-enable-multibyte-characters: t

-- 
Heriot-Watt University is a Scottish charity
registered under charity number SC000278