diff options
| author | Chong Yidong | 2012-05-10 14:27:12 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-05-10 14:27:12 +0800 |
| commit | 9f9aa0448aa1b5317d8903e33db1e3bb27e98ece (patch) | |
| tree | 326360d5b258a5c269c20f12a19a9cead3fbf0f7 /lisp/url | |
| parent | 97107e2e531ee355f517990eed735fa657b7105b (diff) | |
| download | emacs-9f9aa0448aa1b5317d8903e33db1e3bb27e98ece.tar.gz emacs-9f9aa0448aa1b5317d8903e33db1e3bb27e98ece.zip | |
Cleanups and improvements for FFAP and URL.
* ffap.el (ffap-url-unwrap-local): Make it work right.
Use url-generic-parse-url, and handle host names and Windows
filenames properly.
(ffap-url-unwrap-remote): Use url-generic-parse-url.
(ffap-url-unwrap-remote): Accept list values, specifying a list of
URL schemes to work on.
(ffap--toggle-read-only): New function.
(ffap-read-only, ffap-read-only-other-window)
(ffap-read-only-other-frame): Use it.
(ffap-fixup-url): Don't check ffap-ftp-regexp, since it is not
necessary for ffap-url-unwrap-remote.
* url-parse.el (url-path-and-query, url-port-if-non-default): New
functions.
(url-generic-parse-url): Don't set the portspec slot if it is not
specified; that is what `url-port' is for.
(url-port): Only require the scheme to be specified to call
url-scheme-get-property.
* url-util.el (url-encode-url): Use url-path-and-query.
* url-vars.el (url-mime-charset-string): Load mm-util lazily.
Fixes: debbugs:9131
Diffstat (limited to 'lisp/url')
| -rw-r--r-- | lisp/url/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/url/url-parse.el | 64 | ||||
| -rw-r--r-- | lisp/url/url-util.el | 37 | ||||
| -rw-r--r-- | lisp/url/url-vars.el | 3 |
4 files changed, 72 insertions, 46 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index b3669a72ac3..c41df0e832b 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2012-05-10 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * url-parse.el (url-path-and-query, url-port-if-non-default): New | ||
| 4 | functions. | ||
| 5 | (url-generic-parse-url): Don't set the portspec slot if it is not | ||
| 6 | specified; that is what `url-port' is for. | ||
| 7 | (url-port): Only require the scheme to be specified to call | ||
| 8 | url-scheme-get-property. | ||
| 9 | |||
| 10 | * url-util.el (url-encode-url): Use url-path-and-query. | ||
| 11 | |||
| 12 | * url-vars.el (url-mime-charset-string): Load mm-util lazily. | ||
| 13 | |||
| 1 | 2012-05-09 Chong Yidong <cyd@gnu.org> | 14 | 2012-05-09 Chong Yidong <cyd@gnu.org> |
| 2 | 15 | ||
| 3 | * url-util.el (url-encode-url): New function for URL quoting. | 16 | * url-util.el (url-encode-url): New function for URL quoting. |
| @@ -12,6 +25,7 @@ | |||
| 12 | whole path and query inside the FILENAME slot. Improve docstring. | 25 | whole path and query inside the FILENAME slot. Improve docstring. |
| 13 | (url-recreate-url-attributes): Mark as obsolete. | 26 | (url-recreate-url-attributes): Mark as obsolete. |
| 14 | (url-recreate-url): Handle missing scheme and userinfo. | 27 | (url-recreate-url): Handle missing scheme and userinfo. |
| 28 | (url-path-and-query): New function. | ||
| 15 | 29 | ||
| 16 | * url-http.el (url-http-create-request): Ignore obsolete | 30 | * url-http.el (url-http-create-request): Ignore obsolete |
| 17 | attributes slot of url-object. | 31 | attributes slot of url-object. |
diff --git a/lisp/url/url-parse.el b/lisp/url/url-parse.el index 40183a4f533..18c5790313e 100644 --- a/lisp/url/url-parse.el +++ b/lisp/url/url-parse.el | |||
| @@ -39,22 +39,52 @@ | |||
| 39 | silent (use-cookies t)) | 39 | silent (use-cookies t)) |
| 40 | 40 | ||
| 41 | (defsubst url-port (urlobj) | 41 | (defsubst url-port (urlobj) |
| 42 | "Return the port number for the URL specified by URLOBJ." | ||
| 42 | (or (url-portspec urlobj) | 43 | (or (url-portspec urlobj) |
| 43 | (if (url-fullness urlobj) | 44 | (if (url-type urlobj) |
| 44 | (url-scheme-get-property (url-type urlobj) 'default-port)))) | 45 | (url-scheme-get-property (url-type urlobj) 'default-port)))) |
| 45 | 46 | ||
| 46 | (defsetf url-port (urlobj) (port) `(setf (url-portspec ,urlobj) ,port)) | 47 | (defsetf url-port (urlobj) (port) `(setf (url-portspec ,urlobj) ,port)) |
| 47 | 48 | ||
| 49 | (defun url-path-and-query (urlobj) | ||
| 50 | "Return the path and query components of URLOBJ. | ||
| 51 | These two components are store together in the FILENAME slot of | ||
| 52 | the object. The return value of this function is (PATH . QUERY), | ||
| 53 | where each of PATH and QUERY are strings or nil." | ||
| 54 | (let ((name (url-filename urlobj)) | ||
| 55 | path query) | ||
| 56 | (when name | ||
| 57 | (if (string-match "\\?" name) | ||
| 58 | (setq path (substring name 0 (match-beginning 0)) | ||
| 59 | query (substring name (match-end 0))) | ||
| 60 | (setq path name))) | ||
| 61 | (if (equal path "") (setq path nil)) | ||
| 62 | (if (equal query "") (setq query nil)) | ||
| 63 | (cons path query))) | ||
| 64 | |||
| 65 | (defun url-port-if-non-default (urlobj) | ||
| 66 | "Return the port number specified by URLOBJ, if it is not the default. | ||
| 67 | If the specified port number is the default, return nil." | ||
| 68 | (let ((port (url-portspec urlobj)) | ||
| 69 | type) | ||
| 70 | (and port | ||
| 71 | (or (null (setq type (url-type urlobj))) | ||
| 72 | (not (equal port (url-scheme-get-property type 'default-port)))) | ||
| 73 | port))) | ||
| 74 | |||
| 48 | ;;;###autoload | 75 | ;;;###autoload |
| 49 | (defun url-recreate-url (urlobj) | 76 | (defun url-recreate-url (urlobj) |
| 50 | "Recreate a URL string from the parsed URLOBJ." | 77 | "Recreate a URL string from the parsed URLOBJ." |
| 51 | (let ((type (url-type urlobj)) | 78 | (let* ((type (url-type urlobj)) |
| 52 | (user (url-user urlobj)) | 79 | (user (url-user urlobj)) |
| 53 | (pass (url-password urlobj)) | 80 | (pass (url-password urlobj)) |
| 54 | (host (url-host urlobj)) | 81 | (host (url-host urlobj)) |
| 55 | (port (url-portspec urlobj)) | 82 | ;; RFC 3986: "omit the port component and its : delimiter if |
| 56 | (file (url-filename urlobj)) | 83 | ;; port is empty or if its value would be the same as that of |
| 57 | (frag (url-target urlobj))) | 84 | ;; the scheme's default." |
| 85 | (port (url-port-if-non-default urlobj)) | ||
| 86 | (file (url-filename urlobj)) | ||
| 87 | (frag (url-target urlobj))) | ||
| 58 | (concat (if type (concat type ":")) | 88 | (concat (if type (concat type ":")) |
| 59 | (if (url-fullness urlobj) "//") | 89 | (if (url-fullness urlobj) "//") |
| 60 | (if (or user pass) | 90 | (if (or user pass) |
| @@ -62,15 +92,7 @@ | |||
| 62 | (if pass (concat ":" pass)) | 92 | (if pass (concat ":" pass)) |
| 63 | "@")) | 93 | "@")) |
| 64 | host | 94 | host |
| 65 | ;; RFC 3986: "omit the port component and its : delimiter | 95 | (if port (format ":%d" (url-port urlobj))) |
| 66 | ;; if port is empty or if its value would be the same as | ||
| 67 | ;; that of the scheme's default." | ||
| 68 | (and port | ||
| 69 | (or (null type) | ||
| 70 | (not (equal port | ||
| 71 | (url-scheme-get-property type | ||
| 72 | 'default-port)))) | ||
| 73 | (format ":%d" (url-port urlobj))) | ||
| 74 | (or file "/") | 96 | (or file "/") |
| 75 | (if frag (concat "#" frag))))) | 97 | (if frag (concat "#" frag))))) |
| 76 | 98 | ||
| @@ -102,8 +124,8 @@ TARGET is the fragment identifier component (used to refer to a | |||
| 102 | ATTRIBUTES is nil; this slot originally stored the attribute and | 124 | ATTRIBUTES is nil; this slot originally stored the attribute and |
| 103 | value alists for IMAP URIs, but this feature was removed | 125 | value alists for IMAP URIs, but this feature was removed |
| 104 | since it conflicts with RFC 3986. | 126 | since it conflicts with RFC 3986. |
| 105 | FULLNESS is non-nil iff the authority component of the URI is | 127 | FULLNESS is non-nil iff the hierarchical sequence component of |
| 106 | present. | 128 | the URL starts with two slashes, \"//\". |
| 107 | 129 | ||
| 108 | The parser follows RFC 3986, except that it also tries to handle | 130 | The parser follows RFC 3986, except that it also tries to handle |
| 109 | URIs that are not fully specified (e.g. lacking TYPE), and it | 131 | URIs that are not fully specified (e.g. lacking TYPE), and it |
| @@ -174,10 +196,6 @@ parses to | |||
| 174 | (setq port (string-to-number port)))) | 196 | (setq port (string-to-number port)))) |
| 175 | (setq host (downcase host))) | 197 | (setq host (downcase host))) |
| 176 | 198 | ||
| 177 | (and (null port) | ||
| 178 | scheme | ||
| 179 | (setq port (url-scheme-get-property scheme 'default-port))) | ||
| 180 | |||
| 181 | ;; Now point is on the / ? or # which terminates the | 199 | ;; Now point is on the / ? or # which terminates the |
| 182 | ;; authority, or at the end of the URI, or (if there is no | 200 | ;; authority, or at the end of the URI, or (if there is no |
| 183 | ;; authority) at the beginning of the absolute path. | 201 | ;; authority) at the beginning of the absolute path. |
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index 4185c87918e..71bc84cab09 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el | |||
| @@ -418,31 +418,26 @@ should return it unchanged." | |||
| 418 | (user (url-user obj)) | 418 | (user (url-user obj)) |
| 419 | (pass (url-password obj)) | 419 | (pass (url-password obj)) |
| 420 | (host (url-host obj)) | 420 | (host (url-host obj)) |
| 421 | (file (url-filename obj)) | 421 | (path-and-query (url-path-and-query obj)) |
| 422 | (frag (url-target obj)) | 422 | (path (car path-and-query)) |
| 423 | path query) | 423 | (query (cdr path-and-query)) |
| 424 | (frag (url-target obj))) | ||
| 424 | (if user | 425 | (if user |
| 425 | (setf (url-user obj) (url-hexify-string user))) | 426 | (setf (url-user obj) (url-hexify-string user))) |
| 426 | (if pass | 427 | (if pass |
| 427 | (setf (url-password obj) (url-hexify-string pass))) | 428 | (setf (url-password obj) (url-hexify-string pass))) |
| 428 | (when host | 429 | ;; No special encoding for IPv6 literals. |
| 429 | ;; No special encoding for IPv6 literals. | 430 | (and host |
| 430 | (unless (string-match "\\`\\[.*\\]\\'" host) | 431 | (not (string-match "\\`\\[.*\\]\\'" host)) |
| 431 | (setf (url-host obj) | 432 | (setf (url-host obj) |
| 432 | (url-hexify-string host url-host-allowed-chars)))) | 433 | (url-hexify-string host url-host-allowed-chars))) |
| 433 | ;; Split FILENAME slot into its PATH and QUERY components, and | 434 | |
| 434 | ;; encode them separately. The PATH component can contain | 435 | (if path |
| 435 | ;; unreserved characters, %-encodings, and /:@!$&'()*+,;= | 436 | (setq path (url-hexify-string path url-path-allowed-chars))) |
| 436 | (when file | 437 | (if query |
| 437 | (if (string-match "\\?" file) | 438 | (setq query (url-hexify-string query url-query-allowed-chars))) |
| 438 | (setq path (substring file 0 (match-beginning 0)) | 439 | (setf (url-filename obj) (if query (concat path "?" query) path)) |
| 439 | query (substring file (match-end 0))) | 440 | |
| 440 | (setq path file)) | ||
| 441 | (setq path (url-hexify-string path url-path-allowed-chars)) | ||
| 442 | (if query | ||
| 443 | (setq query (url-hexify-string query url-query-allowed-chars))) | ||
| 444 | (setf (url-filename obj) | ||
| 445 | (if query (concat path "?" query) path))) | ||
| 446 | (if frag | 441 | (if frag |
| 447 | (setf (url-target obj) | 442 | (setf (url-target obj) |
| 448 | (url-hexify-string frag url-query-allowed-chars))) | 443 | (url-hexify-string frag url-query-allowed-chars))) |
diff --git a/lisp/url/url-vars.el b/lisp/url/url-vars.el index 0d71910849f..6aa14b8bae1 100644 --- a/lisp/url/url-vars.el +++ b/lisp/url/url-vars.el | |||
| @@ -21,8 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | 23 | ||
| 24 | (require 'mm-util) | ||
| 25 | |||
| 26 | (defconst url-version "Emacs" | 24 | (defconst url-version "Emacs" |
| 27 | "Version number of URL package.") | 25 | "Version number of URL package.") |
| 28 | 26 | ||
| @@ -221,6 +219,7 @@ Should be an assoc list of headers/contents.") | |||
| 221 | (defun url-mime-charset-string () | 219 | (defun url-mime-charset-string () |
| 222 | "Generate a list of preferred MIME charsets for HTTP requests. | 220 | "Generate a list of preferred MIME charsets for HTTP requests. |
| 223 | Generated according to current coding system priorities." | 221 | Generated according to current coding system priorities." |
| 222 | (require 'mm-util) | ||
| 224 | (if (fboundp 'sort-coding-systems) | 223 | (if (fboundp 'sort-coding-systems) |
| 225 | (let ((ordered (sort-coding-systems | 224 | (let ((ordered (sort-coding-systems |
| 226 | (let (accum) | 225 | (let (accum) |