emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 83f0d60: Don’t adjust CRLF in file names


From: Paul Eggert
Subject: [Emacs-diffs] master 83f0d60: Don’t adjust CRLF in file names
Date: Sat, 19 Aug 2017 20:17:15 -0400 (EDT)

branch: master
commit 83f0d60e498c9cab59e098af6d9c403631ad645c
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Don’t adjust CRLF in file names
    
    * doc/misc/gnus.texi (Non-ASCII Group Names):
    * etc/NEWS:
    * test/lisp/net/tramp-tests.el (tramp--test-utf8):
    Use utf-8-unix, not utf-8, for default-file-name-coding-system, so
    that CRLF in file names is left alone.
    * lisp/international/mule-cmds.el (set-default-coding-systems):
    Do not alter CRLF in file name coding systems.
    (prefer-coding-system): Ignore differences in CRLF processing when
    checking whether we used the user-specified file name coding system.
    * test/src/fileio-tests.el: New file.
---
 doc/misc/gnus.texi              |  4 ++--
 etc/NEWS                        |  6 +++++
 lisp/international/mule-cmds.el | 15 +++++++------
 test/lisp/net/tramp-tests.el    |  3 ++-
 test/src/fileio-tests.el        | 49 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index e00e173..cd94156 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -4340,10 +4340,10 @@ does not necessarily need to be the same value that is 
determined by
 @code{gnus-group-name-charset-group-alist}.
 
 If @code{default-file-name-coding-system} or this variable is
-initialized by default to @code{iso-latin-1} for example, although you
+initialized by default to @code{iso-latin-1-unix} for example, although you
 want to subscribe to the groups spelled in Chinese, that is the most
 typical case where you have to customize
address@hidden  The @code{utf-8} coding system is
address@hidden  The @code{utf-8-unix} coding system is
 a good candidate for it.  Otherwise, you may change the locale in your
 system so that @code{default-file-name-coding-system} or this variable
 may be initialized to an appropriate value.
diff --git a/etc/NEWS b/etc/NEWS
index 259b4ce..7774d75 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1198,6 +1198,12 @@ accepts Lisp symbols which begin with the following 
quotation
 characters: ‘’‛“”‟〞"', unless they are escaped with backslash.
 
 +++
+** 'default-file-name-coding-system' now defaults to a coding system
+that does not process CRLF.  For example, it defaults to utf-8-unix
+instead of to utf-8.  Before this change, Emacs would sometimes
+mishandle file names containing these control characters.
+
++++
 ** Module functions are now implemented slightly differently; in
 particular, the function 'internal--module-call' has been removed.
 Code that depends on undocumented internals of the module system might
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index ee31dea..338ca6a 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -354,11 +354,12 @@ This also sets the following values:
 
   (if (eq system-type 'darwin)
       ;; The file-name coding system on Darwin systems is always utf-8.
-      (setq default-file-name-coding-system 'utf-8)
+      (setq default-file-name-coding-system 'utf-8-unix)
     (if (and (default-value 'enable-multibyte-characters)
             (or (not coding-system)
                 (coding-system-get coding-system 'ascii-compatible-p)))
-       (setq default-file-name-coding-system coding-system)))
+       (setq default-file-name-coding-system
+             (coding-system-change-eol-conversion coding-system 'unix))))
   (setq default-terminal-coding-system coding-system)
   ;; Prevent default-terminal-coding-system from converting ^M to ^J.
   (setq default-keyboard-coding-system
@@ -414,7 +415,7 @@ To prefer, for instance, utf-8, say the following:
              (coding-system-change-eol-conversion base eol-type)))
     (set-default-coding-systems base)
     (if (called-interactively-p 'interactive)
-       (or (eq base default-file-name-coding-system)
+       (or (eq base (coding-system-type default-file-name-coding-system))
            (message "The default value of `file-name-coding-system' was not 
changed because the specified coding system is not suitable for file 
names.")))))
 
 (defvar sort-coding-systems-predicate nil
@@ -1797,9 +1798,9 @@ The default status is as follows:
 
   (set-default-coding-systems nil)
   (setq default-sendmail-coding-system 'iso-latin-1)
-  ;; On Darwin systems, this should be utf-8, but when this file is loaded
-  ;; utf-8 is not yet defined, so we set it in set-locale-environment instead.
-  (setq default-file-name-coding-system 'iso-latin-1)
+  ;; On Darwin systems, this should be utf-8-unix, but when this file is loaded
+  ;; that is not yet defined, so we set it in set-locale-environment instead.
+  (setq default-file-name-coding-system 'iso-latin-1-unix)
   ;; Preserve eol-type from existing default-process-coding-systems.
   ;; On non-unix-like systems in particular, these may have been set
   ;; carefully by the user, or by the startup code, to deal with the
@@ -2722,7 +2723,7 @@ See also `locale-charset-language-names', 
`locale-language-names',
     (when (eq system-type 'darwin)
       ;; On Darwin, file names are always encoded in utf-8, no matter
       ;; the locale.
-      (setq default-file-name-coding-system 'utf-8)
+      (setq default-file-name-coding-system 'utf-8-unix)
       ;; macOS's Terminal.app by default uses utf-8 regardless of
       ;; the locale.
       (when (and (null window-system)
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 9d2598a..9dc276b 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -3719,7 +3719,8 @@ Use the `ls' command."
                   'utf-8-hfs 'utf-8))
         (coding-system-for-read utf8)
         (coding-system-for-write utf8)
-        (file-name-coding-system utf8))
+        (file-name-coding-system
+         (coding-system-change-eol-conversion utf8 'unix)))
     (tramp--test-check-files
      (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
      (unless (tramp--test-hpux-p)
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
new file mode 100644
index 0000000..75aca7d
--- /dev/null
+++ b/test/src/fileio-tests.el
@@ -0,0 +1,49 @@
+;;; unit tests for src/fileio.c      -*- lexical-binding: t; -*-
+
+;; Copyright 2017 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+(require 'ert)
+
+(defun try-char (char link)
+  (let ((target (string char)))
+    (make-symbolic-link target link)
+    (let* ((read-link (file-symlink-p link))
+           (failure (unless (string-equal target read-link)
+                      (list 'string-equal target read-link))))
+      (delete-file link)
+      failure)))
+
+(defun fileio-tests--symlink-failure ()
+  (let* ((dir (make-temp-file "fileio" t))
+         (link (expand-file-name "link" dir)))
+    (unwind-protect
+        (let ((failure
+               (let ((default-file-name-coding-system 'utf-8-unix))
+                 (try-char (unibyte-char-to-multibyte 128) link)))
+              (char 0))
+          (while (and (not failure) (< char 300))
+            (setq char (1+ char))
+            (unless (= char ?~)
+              (setq failure (try-char char link))))
+          failure)
+      (delete-directory dir t))))
+
+(ert-deftest fileio-tests--odd-symlink-chars ()
+  "Check that any non-NULL ASCII character can appear in a symlink.
+Also check that an encoding error can appear in a symlink."
+  (should (equal nil (fileio-tests--symlink-failure))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]