aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/files.el17
1 files changed, 10 insertions, 7 deletions
diff --git a/lisp/files.el b/lisp/files.el
index be98b3c8562..840ab2f77fa 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4561,15 +4561,18 @@ See also `auto-save-file-name-p'."
4561 (let ((buffer-name (buffer-name)) 4561 (let ((buffer-name (buffer-name))
4562 (limit 0) 4562 (limit 0)
4563 file-name) 4563 file-name)
4564 ;; Eliminate all slashes and backslashes by 4564 ;; Restrict the characters used in the file name to those which
4565 ;; replacing them with sequences that start with %. 4565 ;; are known to be safe on all filesystems, url-encoding the
4566 ;; Quote % also, to keep distinct names distinct. 4566 ;; rest.
4567 (while (string-match "[/\\%]" buffer-name limit) 4567 ;; We do this on all platforms, because even if we are not
4568 ;; running on DOS/Windows, the current directory may be on a
4569 ;; mounted VFAT filesystem, such as a USB memory stick.
4570 (while (string-match "[^A-Za-z0-9-_.~#+]" buffer-name limit)
4568 (let* ((character (aref buffer-name (match-beginning 0))) 4571 (let* ((character (aref buffer-name (match-beginning 0)))
4569 (replacement 4572 (replacement
4570 (cond ((eq character ?%) "%%") 4573 ;; For multibyte characters, this will produce more than
4571 ((eq character ?/) "%+") 4574 ;; 2 hex digits, so is not true URL encoding.
4572 ((eq character ?\\) "%-")))) 4575 (format "%%%02X" character)))
4573 (setq buffer-name (replace-match replacement t t buffer-name)) 4576 (setq buffer-name (replace-match replacement t t buffer-name))
4574 (setq limit (1+ (match-end 0))))) 4577 (setq limit (1+ (match-end 0)))))
4575 ;; Generate the file name. 4578 ;; Generate the file name.