unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7680: 23.2.91; [PATCH] dnd-get-local-file-name bug
@ 2010-12-19 14:19 Leo
  2010-12-20  7:07 ` Jan Djärv
  0 siblings, 1 reply; 4+ messages in thread
From: Leo @ 2010-12-19 14:19 UTC (permalink / raw)
  To: 7680


I just noticed the return value of dnd-get-local-file-name may contain
%20 etc. The patch fixes this.

commit 8d987eb074d6ff8282ce3fdc19f00cdb82fdfa28 (HEAD, refs/heads/leo-main)
Date:   Sun Dec 19 14:12:55 2010 +0000

    Unhex file name should always be performed
    
    in dnd-get-local-file-name.
---
 lisp/dnd.el |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

	Modified lisp/dnd.el
diff --git a/lisp/dnd.el b/lisp/dnd.el
index aadfad6..e6e3190 100644
--- a/lisp/dnd.el
+++ b/lisp/dnd.el
@@ -143,14 +143,14 @@ Return nil if URI is not a local file."
 		  (substring uri (1- (match-end 0))))
 		 ((string-match "^file:" uri)		; Old KDE, Motif, Sun
 		  (substring uri (match-end 0))))))
+    (and f (setq f (replace-regexp-in-string
+		    "%[A-Fa-f0-9][A-Fa-f0-9]"
+		    (lambda (arg)
+		      (let ((str (make-string 1 0)))
+			(aset str 0 (string-to-number (substring arg 1) 16))
+			str))
+		    f t t)))
     (when (and f must-exist)
-      (setq f (replace-regexp-in-string
-	       "%[A-Fa-f0-9][A-Fa-f0-9]"
-	       (lambda (arg)
-		 (let ((str (make-string 1 0)))
-		   (aset str 0 (string-to-number (substring arg 1) 16))
-		   str))
-	       f t t))
       (let* ((decoded-f (decode-coding-string
 			 f
 			 (or file-name-coding-system






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

* bug#7680: 23.2.91; [PATCH] dnd-get-local-file-name bug
  2010-12-19 14:19 bug#7680: 23.2.91; [PATCH] dnd-get-local-file-name bug Leo
@ 2010-12-20  7:07 ` Jan Djärv
  2010-12-20  8:56   ` Leo
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Djärv @ 2010-12-20  7:07 UTC (permalink / raw)
  To: Leo; +Cc: 7680

To conform to the policy in 
http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html we should 
also decode it with the file name coding system when must-exist is nil. 
AFAIK, dnd-get-local-file-name is only called with must-exist t.

	Jan D.


Leo skrev 2010-12-19 15.19:
>
> I just noticed the return value of dnd-get-local-file-name may contain
> %20 etc. The patch fixes this.
>
> commit 8d987eb074d6ff8282ce3fdc19f00cdb82fdfa28 (HEAD, refs/heads/leo-main)
> Date:   Sun Dec 19 14:12:55 2010 +0000
>
>      Unhex file name should always be performed
>
>      in dnd-get-local-file-name.
> ---
>   lisp/dnd.el |   14 +++++++-------
>   1 files changed, 7 insertions(+), 7 deletions(-)
>
> 	Modified lisp/dnd.el
> diff --git a/lisp/dnd.el b/lisp/dnd.el
> index aadfad6..e6e3190 100644
> --- a/lisp/dnd.el
> +++ b/lisp/dnd.el
> @@ -143,14 +143,14 @@ Return nil if URI is not a local file."
>   		  (substring uri (1- (match-end 0))))
>   		 ((string-match "^file:" uri)		; Old KDE, Motif, Sun
>   		  (substring uri (match-end 0))))))
> +    (and f (setq f (replace-regexp-in-string
> +		    "%[A-Fa-f0-9][A-Fa-f0-9]"
> +		    (lambda (arg)
> +		      (let ((str (make-string 1 0)))
> +			(aset str 0 (string-to-number (substring arg 1) 16))
> +			str))
> +		    f t t)))
>       (when (and f must-exist)
> -      (setq f (replace-regexp-in-string
> -	       "%[A-Fa-f0-9][A-Fa-f0-9]"
> -	       (lambda (arg)
> -		 (let ((str (make-string 1 0)))
> -		   (aset str 0 (string-to-number (substring arg 1) 16))
> -		   str))
> -	       f t t))
>         (let* ((decoded-f (decode-coding-string
>   			 f
>   			 (or file-name-coding-system
>
>
>





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

* bug#7680: 23.2.91; [PATCH] dnd-get-local-file-name bug
  2010-12-20  7:07 ` Jan Djärv
@ 2010-12-20  8:56   ` Leo
  2010-12-20 20:11     ` Jan Djärv
  0 siblings, 1 reply; 4+ messages in thread
From: Leo @ 2010-12-20  8:56 UTC (permalink / raw)
  To: bug-gnu-emacs

On 2010-12-20 07:07 +0000, Jan Djärv wrote:
> To conform to the policy in
> http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html we
> should also decode it with the file name coding system when must-exist
> is nil. AFAIK, dnd-get-local-file-name is only called with must-exist
> t.
>
> 	Jan D.

OK. The original dnd-get-local-file-name could return an uncoded file
name. Should that be kept? In the attached patch, I assume returned file
name should always be decoded.

diff --git a/lisp/dnd.el b/lisp/dnd.el
index aadfad6..e508d52 100644
--- a/lisp/dnd.el
+++ b/lisp/dnd.el
@@ -134,6 +134,16 @@ Return nil if URI is not a local file."
 		 (string-equal system-name-no-dot hostname)))
 	(concat "file://" (substring uri (+ 7 (length hostname)))))))
 
+(defsubst dnd-unescape-uri (uri)
+  (replace-regexp-in-string
+   "%[A-Fa-f0-9][A-Fa-f0-9]"
+   (lambda (arg)
+     (let ((str (make-string 1 0)))
+       (aset str 0 (string-to-number (substring arg 1) 16))
+       str))
+   uri t t))
+
+;; http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html
 (defun dnd-get-local-file-name (uri &optional must-exist)
   "Return file name converted from file:/// or file: syntax.
 URI is the uri for the file.  If MUST-EXIST is given and non-nil,
@@ -143,21 +153,11 @@ Return nil if URI is not a local file."
 		  (substring uri (1- (match-end 0))))
 		 ((string-match "^file:" uri)		; Old KDE, Motif, Sun
 		  (substring uri (match-end 0))))))
-    (when (and f must-exist)
-      (setq f (replace-regexp-in-string
-	       "%[A-Fa-f0-9][A-Fa-f0-9]"
-	       (lambda (arg)
-		 (let ((str (make-string 1 0)))
-		   (aset str 0 (string-to-number (substring arg 1) 16))
-		   str))
-	       f t t))
-      (let* ((decoded-f (decode-coding-string
-			 f
-			 (or file-name-coding-system
-			     default-file-name-coding-system))))
-	(setq f (cond ((file-readable-p decoded-f) decoded-f)
-		      ((file-readable-p f) f)
-		      (t nil)))))
+    (and f (setq f (decode-coding-string (dnd-unescape-uri f)
+                                         (or file-name-coding-system
+                                             default-file-name-coding-system))))
+    (when (and f must-exist (not (file-readable-p f)))
+      (setq f nil))
     f))
 
 (defun dnd-open-local-file (uri action)








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

* bug#7680: 23.2.91; [PATCH] dnd-get-local-file-name bug
  2010-12-20  8:56   ` Leo
@ 2010-12-20 20:11     ` Jan Djärv
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Djärv @ 2010-12-20 20:11 UTC (permalink / raw)
  To: Leo; +Cc: bug-gnu-emacs, 7680-done



Leo skrev 2010-12-20 09.56:
> On 2010-12-20 07:07 +0000, Jan Djärv wrote:
>> To conform to the policy in
>> http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html we
>> should also decode it with the file name coding system when must-exist
>> is nil. AFAIK, dnd-get-local-file-name is only called with must-exist
>> t.
>>
>> 	Jan D.
>
> OK. The original dnd-get-local-file-name could return an uncoded file
> name. Should that be kept? In the attached patch, I assume returned file
> name should always be decoded.

It is better the way you have it now, i.e. always return a decoded file name.
It is confusing if it can return two things.  Installed.


	Jan D.

> diff --git a/lisp/dnd.el b/lisp/dnd.el
> index aadfad6..e508d52 100644
> --- a/lisp/dnd.el
> +++ b/lisp/dnd.el
> @@ -134,6 +134,16 @@ Return nil if URI is not a local file."
>   		 (string-equal system-name-no-dot hostname)))
>   	(concat "file://" (substring uri (+ 7 (length hostname)))))))
>
> +(defsubst dnd-unescape-uri (uri)
> +  (replace-regexp-in-string
> +   "%[A-Fa-f0-9][A-Fa-f0-9]"
> +   (lambda (arg)
> +     (let ((str (make-string 1 0)))
> +       (aset str 0 (string-to-number (substring arg 1) 16))
> +       str))
> +   uri t t))
> +
> +;; http://lists.gnu.org/archive/html/emacs-devel/2006-05/msg01060.html
>   (defun dnd-get-local-file-name (uri&optional must-exist)
>     "Return file name converted from file:/// or file: syntax.
>   URI is the uri for the file.  If MUST-EXIST is given and non-nil,
> @@ -143,21 +153,11 @@ Return nil if URI is not a local file."
>   		  (substring uri (1- (match-end 0))))
>   		 ((string-match "^file:" uri)		; Old KDE, Motif, Sun
>   		  (substring uri (match-end 0))))))
> -    (when (and f must-exist)
> -      (setq f (replace-regexp-in-string
> -	       "%[A-Fa-f0-9][A-Fa-f0-9]"
> -	       (lambda (arg)
> -		 (let ((str (make-string 1 0)))
> -		   (aset str 0 (string-to-number (substring arg 1) 16))
> -		   str))
> -	       f t t))
> -      (let* ((decoded-f (decode-coding-string
> -			 f
> -			 (or file-name-coding-system
> -			     default-file-name-coding-system))))
> -	(setq f (cond ((file-readable-p decoded-f) decoded-f)
> -		      ((file-readable-p f) f)
> -		      (t nil)))))
> +    (and f (setq f (decode-coding-string (dnd-unescape-uri f)
> +                                         (or file-name-coding-system
> +                                             default-file-name-coding-system))))
> +    (when (and f must-exist (not (file-readable-p f)))
> +      (setq f nil))
>       f))
>
>   (defun dnd-open-local-file (uri action)
>
>
>
>
>





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

end of thread, other threads:[~2010-12-20 20:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-19 14:19 bug#7680: 23.2.91; [PATCH] dnd-get-local-file-name bug Leo
2010-12-20  7:07 ` Jan Djärv
2010-12-20  8:56   ` Leo
2010-12-20 20:11     ` Jan Djärv

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).