unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#21454: 25.0.50; `parse-colon-path' fails with paths containing consecutive directory separators
@ 2015-09-10 11:15 Tino Calancha
  2015-09-10 12:48 ` bug#21454: (no subject) Tino Calancha
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Tino Calancha @ 2015-09-10 11:15 UTC (permalink / raw)
  To: 21454; +Cc: C. Calancha

[-- Attachment #1: Type: text/plain, Size: 5413 bytes --]



Implementation use `substitute-in-file-name' which substitute environment variables but 
also drop all in front of consecutive directory separators (up to the last 
of those dir. separators). The documentation of `parse-colon-path' dont 
mention about that behaviour.

In unix systems there is no difference between:

I)  /foo//bar/baz
II) /foo/bar/baz

`substitute-in-file-name' would translate I) into:
/bar/baz

In case path to parse contains an environment variable:
FOO=/foo/bar
BAZ=/foo/bar/

A) path="$FOO/bin" ; works (FOO is a directory file name)
B) path="$BAZ/bin" ; fails (FOO is not a directory file name)


Observed same behaviour on this fuction in emacs versions: 19, 20, 21, 22, 
23, 24 and 25.
Attached patch calls `substitute-env-in-file-name' instead of 
`substitute-in-file-name' and it returns same values for 
inputs I) and II) or A) and B).

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In *scratch* buffer after started session with:
emacs -Q

(let* ((foo "/foo/bar//baz/:/qux/quux/corge//")) ; '//'
   (setenv "FOO" foo)
   (parse-colon-path (getenv "FOO")))
("/baz/" "/")

(let ((foo "/foo/bar/baz/qux/:/quux/corge/:/grault/graply/waldo")) ; `ok'
   (setenv "FOO" foo)
   (parse-colon-path "$FOO"))
("/foo/bar/baz/qux/:/quux/corge/:/grault/graply/waldo/")

(let ((foo "/foo/bar/baz/qux/:/quux/corge/:/grault/graply/waldo/")) ; end with '/' and `parse-colon-path' add another
   (setenv "FOO" foo)
   (parse-colon-path "$FOO"))
("/")

(let ((foo "/foo/bar/baz/qux/:/quux/corge/:/grault/graply/waldo/")) ; `getenv' makes it work somehow
   (setenv "FOO" foo)
   (parse-colon-path (getenv "FOO")))
("/foo/bar/baz/qux/" "/quux/corge/" "/grault/graply/waldo/")

(let ((foo "/foo/bar/baz//qux/:/quux/corge/:/grault/garply/waldo/")) ; `getenv' dont help with '//'
   (setenv "FOO" foo)
   (parse-colon-path (getenv "FOO")))
("/qux/" "/quux/corge/" "/grault/garply/waldo/")

(let ((foo "/foo/bar/baz//qux/:/quux/corge/:/grault/garply/waldo")) ; '//'
   (setenv "FOO" foo)
   (parse-colon-path "$FOO"))
("/qux/:/quux/corge/:/grault/garply/waldo/")

(let* ((foo "/foo/bar")                    ; `ok' foo not end with '/'
        (bar "$FOO/baz/qux/:/quux/corge/"))
   (setenv "FOO" foo)
   (setenv "BAR" bar)
   (parse-colon-path (getenv "BAR")))
("/foo/bar/baz/qux/" "/quux/corge/")

(let* ((foo "/foo/bar/")                   ; foo ends with '/'
 	   (bar "$FOO/baz/qux/:/quux/corge/"))
   (setenv "FOO" foo)
   (setenv "BAR" bar)
   (parse-colon-path (getenv "BAR")))
("/baz/qux/" "/quux/corge/")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.23)
  of 2015-09-10
Repository revision: f962c5d6472804f788cdd54631bcc46aab5f59ce
Windowing system distributor 'Scientific Linux', version 11.0.11500000
System Description:	Scientific Linux release 6.7 (Carbon)

Configured using:
  'configure --without-makeinfo --with-gif=no'

Configured features:
XPM JPEG TIFF PNG IMAGEMAGICK SOUND DBUS GCONF NOTIFY LIBSELINUX LIBXML2
FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS GTK2 X11

Important settings:
   value of $LANG: en_US.utf8
   value of $XMODIFIERS: @im=none
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
<backtab> is undefined
Quit
completing-read-default: Command attempted to use minibuffer while in minibuffer
user-error: Beginning of history; no preceding item
Quit [2 times]

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns help-mode easymenu cl-loaddefs pcase cl-lib mail-prsvr
mail-utils time-date mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind inotify
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 80421 12421)
  (symbols 48 18940 0)
  (miscs 40 39 110)
  (strings 32 12495 3997)
  (string-bytes 1 361986)
  (vectors 16 11158)
  (vector-slots 8 408984 7901)
  (floats 8 131 123)
  (intervals 56 192 0)
  (buffers 976 12)
  (heap 1024 26696 621))

[-- Attachment #2: Type: text/plain, Size: 1382 bytes --]

--- files.el	2015-09-10 19:31:06.569650962 +0900
+++ files_patched.el	2015-09-10 20:01:00.303650748 +0900
@@ -667,7 +667,8 @@
   "Value of the CDPATH environment variable, as a list.
 Not actually set up until the first time you use it.")
 
-(defun parse-colon-path (search-path)
+(require 'env)
+(defun myparse-colon-path2 (search-path)
   "Explode a search path into a list of directory names.
 Directories are separated by `path-separator' (which is colon in
 GNU and Unix systems).  Substitute environment variables into the
@@ -675,10 +676,12 @@
 a leading or trailing separator, or two adjacent separators), return
 nil (meaning `default-directory') as the associated list element."
   (when (stringp search-path)
-    (mapcar (lambda (f)
-	      (if (equal "" f) nil
-		(substitute-in-file-name (file-name-as-directory f))))
-	    (split-string search-path path-separator))))
+    (let* ((path-list        (mapcar 'substitute-env-vars (split-string search-path path-separator)))
+           (search-path-sub  (mapconcat 'identity path-list path-separator)))
+      (mapcar (lambda (f)
+                (if (equal "" f) nil
+                  (expand-file-name (file-name-as-directory f))))
+              (split-string search-path-sub path-separator)))))
 
 (defun cd-absolute (dir)
   "Change current directory to given absolute file name DIR."

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-08-12 12:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-10 11:15 bug#21454: 25.0.50; `parse-colon-path' fails with paths containing consecutive directory separators Tino Calancha
2015-09-10 12:48 ` bug#21454: (no subject) Tino Calancha
2016-04-24 17:26 ` bug#21454: 25.0.93; `parse-colon-path' over dirs with 2 consecutive dir sep Tino Calancha
2016-09-13  8:55 ` bug#21454: 25.1.50; `parse-colon-path' fails with file names containing multiple consecutive "/" Tino Calancha
2016-09-13  9:16   ` Andreas Schwab
2016-09-13  9:40     ` Tino Calancha
2017-08-31  1:09       ` npostavs
2019-06-25 15:28       ` Lars Ingebrigtsen
2019-06-25 16:29         ` Andreas Schwab
2020-08-12 12:54           ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).