diff options
| author | Paul Eggert | 2012-04-21 17:53:32 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-04-21 17:53:32 -0700 |
| commit | bbd347f5f7e99da1a559dad818b5fa8f59c0901e (patch) | |
| tree | 77c1fc54c2240b08d2859109d18cac8812a8ffb1 /lisp/url | |
| parent | e4ecdc9c71af4199129d5dd2db1a32ff6b725fe4 (diff) | |
| parent | 9ee7d8b93cb143b473e6dffb708e777bc6fe5bd0 (diff) | |
| download | emacs-bbd347f5f7e99da1a559dad818b5fa8f59c0901e.tar.gz emacs-bbd347f5f7e99da1a559dad818b5fa8f59c0901e.zip | |
Merge from trunk.
Diffstat (limited to 'lisp/url')
| -rw-r--r-- | lisp/url/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/url/url-cookie.el | 45 | ||||
| -rw-r--r-- | lisp/url/url-domsuf.el | 98 | ||||
| -rw-r--r-- | lisp/url/url-util.el | 3 | ||||
| -rw-r--r-- | lisp/url/url.el | 11 |
5 files changed, 139 insertions, 36 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index d6e25188c69..3c9313e3e7d 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2012-04-10 William Xu <william.xwl@gmail.com> (tiny change) | ||
| 2 | |||
| 3 | * url.el (url-retrieve-internal): Hexify multibye URL string first | ||
| 4 | when necessary (bug#7017). | ||
| 5 | |||
| 6 | 2012-04-10 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 7 | |||
| 8 | * url.el (url-retrieve-internal): Mention utf-8 encoding. | ||
| 9 | (url-retrieve): Ditto. | ||
| 10 | |||
| 11 | 2012-04-10 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 12 | |||
| 13 | * url-domsurf.el: New file (bug#1401). | ||
| 14 | |||
| 15 | * url-cookie.el (url-cookie-two-dot-domains): Remove. | ||
| 16 | (url-cookie-host-can-set-p): Use `url-domsuf-cookie-allowed-p' | ||
| 17 | instead of the variable above. | ||
| 18 | |||
| 1 | 2012-03-25 Lars Magne Ingebrigtsen <larsi@gnus.org> | 19 | 2012-03-25 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 20 | ||
| 3 | * url-queue.el (url-queue-kill-job): Check whether the buffer has | 21 | * url-queue.el (url-queue-kill-job): Check whether the buffer has |
diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el index e6ff9bf7dea..aefe8fffd0a 100644 --- a/lisp/url/url-cookie.el +++ b/lisp/url/url-cookie.el | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | (require 'url-util) | 26 | (require 'url-util) |
| 27 | (require 'url-parse) | 27 | (require 'url-parse) |
| 28 | (require 'url-domsuf) | ||
| 28 | 29 | ||
| 29 | (eval-when-compile (require 'cl)) ; defstruct | 30 | (eval-when-compile (require 'cl)) ; defstruct |
| 30 | 31 | ||
| @@ -211,14 +212,6 @@ telling Microsoft that." | |||
| 211 | (concat retval "\r\n") | 212 | (concat retval "\r\n") |
| 212 | ""))) | 213 | ""))) |
| 213 | 214 | ||
| 214 | (defvar url-cookie-two-dot-domains | ||
| 215 | (concat "\\.\\(" | ||
| 216 | (mapconcat 'identity (list "com" "edu" "net" "org" "gov" "mil" "int") | ||
| 217 | "\\|") | ||
| 218 | "\\)$") | ||
| 219 | "A regexp of top level domains that only require two matching | ||
| 220 | '.'s in the domain name in order to set a cookie.") | ||
| 221 | |||
| 222 | (defcustom url-cookie-trusted-urls nil | 215 | (defcustom url-cookie-trusted-urls nil |
| 223 | "A list of regular expressions matching URLs to always accept cookies from." | 216 | "A list of regular expressions matching URLs to always accept cookies from." |
| 224 | :type '(repeat regexp) | 217 | :type '(repeat regexp) |
| @@ -230,30 +223,18 @@ telling Microsoft that." | |||
| 230 | :group 'url-cookie) | 223 | :group 'url-cookie) |
| 231 | 224 | ||
| 232 | (defun url-cookie-host-can-set-p (host domain) | 225 | (defun url-cookie-host-can-set-p (host domain) |
| 233 | (let ((numdots 0) | 226 | (let ((last nil) |
| 234 | (last nil) | 227 | (case-fold-search t)) |
| 235 | (case-fold-search t) | 228 | (if (string= host domain) ; Apparently netscape lets you do this |
| 236 | (mindots 3)) | 229 | t |
| 237 | (while (setq last (string-match "\\." domain last)) | 230 | ;; Remove the dot from wildcard domains before matching. |
| 238 | (setq numdots (1+ numdots) | 231 | (when (eq ?. (aref domain 0)) |
| 239 | last (1+ last))) | 232 | (setq domain (substring domain 1))) |
| 240 | (if (string-match url-cookie-two-dot-domains domain) | 233 | (and (url-domsuf-cookie-allowed-p domain) |
| 241 | (setq mindots 2)) | 234 | ;; Need to check and make sure the host is actually _in_ the |
| 242 | (cond | 235 | ;; domain it wants to set a cookie for though. |
| 243 | ((string= host domain) ; Apparently netscape lets you do this | 236 | (string-match (concat (regexp-quote domain) |
| 244 | t) | 237 | "$") host))))) |
| 245 | ((>= numdots mindots) ; We have enough dots in domain name | ||
| 246 | ;; Need to check and make sure the host is actually _in_ the | ||
| 247 | ;; domain it wants to set a cookie for though. | ||
| 248 | (string-match (concat (regexp-quote | ||
| 249 | ;; Remove the dot from wildcard domains | ||
| 250 | ;; before matching. | ||
| 251 | (if (eq ?. (aref domain 0)) | ||
| 252 | (substring domain 1) | ||
| 253 | domain)) | ||
| 254 | "$") host)) | ||
| 255 | (t | ||
| 256 | nil)))) | ||
| 257 | 238 | ||
| 258 | (defun url-cookie-handle-set-cookie (str) | 239 | (defun url-cookie-handle-set-cookie (str) |
| 259 | (setq url-cookies-changed-since-last-save t) | 240 | (setq url-cookies-changed-since-last-save t) |
diff --git a/lisp/url/url-domsuf.el b/lisp/url/url-domsuf.el new file mode 100644 index 00000000000..29fc166e30b --- /dev/null +++ b/lisp/url/url-domsuf.el | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | ;;; url-domsuf.el --- Say what domain names can have cookies set. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2012 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 6 | |||
| 7 | ;; Keywords: comm, data, processes, hypermedia | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | ;; | ||
| 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 12 | ;; it under the terms of the GNU General Public License as published by | ||
| 13 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 14 | ;; (at your option) any later version. | ||
| 15 | |||
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ;; GNU General Public License for more details. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 23 | |||
| 24 | ;;; Commentary: | ||
| 25 | |||
| 26 | ;; The rules for what domains can have cookies set is defined here: | ||
| 27 | ;; http://publicsuffix.org/list/ | ||
| 28 | |||
| 29 | ;;; Code: | ||
| 30 | |||
| 31 | (defvar url-domsuf-domains nil) | ||
| 32 | |||
| 33 | (defun url-domsuf-parse-file () | ||
| 34 | (with-temp-buffer | ||
| 35 | (insert-file-contents | ||
| 36 | (expand-file-name "publicsuffix.txt" data-directory)) | ||
| 37 | (let ((domains nil) | ||
| 38 | domain exception) | ||
| 39 | (while (not (eobp)) | ||
| 40 | (when (not (looking-at "[/\n\t ]")) | ||
| 41 | ;; !pref.aichi.jp means that it's allowed. | ||
| 42 | (if (not (eq (following-char) ?!)) | ||
| 43 | (setq exception nil) | ||
| 44 | (setq exception t) | ||
| 45 | (forward-char 1)) | ||
| 46 | (setq domain (buffer-substring (point) (line-end-position))) | ||
| 47 | (cond | ||
| 48 | ((string-match "\\`\\*\\." domain) | ||
| 49 | (setq domain (substring domain 2)) | ||
| 50 | (push (cons domain (1+ (length (split-string domain "[.]")))) | ||
| 51 | domains)) | ||
| 52 | (exception | ||
| 53 | (push (cons domain t) domains)) | ||
| 54 | (t | ||
| 55 | (push (cons domain nil) domains)))) | ||
| 56 | (forward-line 1)) | ||
| 57 | (setq url-domsuf-domains (nreverse domains))))) | ||
| 58 | |||
| 59 | (defun url-domsuf-cookie-allowed-p (domain) | ||
| 60 | (unless url-domsuf-domains | ||
| 61 | (url-domsuf-parse-file)) | ||
| 62 | (let* ((allowedp t) | ||
| 63 | (domain-bits (split-string domain "[.]")) | ||
| 64 | (length (length domain-bits)) | ||
| 65 | (upper-domain (mapconcat 'identity (cdr domain-bits) ".")) | ||
| 66 | entry modifier) | ||
| 67 | (dolist (elem url-domsuf-domains) | ||
| 68 | (setq entry (car elem) | ||
| 69 | modifier (cdr elem)) | ||
| 70 | (cond | ||
| 71 | ;; "com" | ||
| 72 | ((and (null modifier) | ||
| 73 | (string= domain entry)) | ||
| 74 | (setq allowedp nil)) | ||
| 75 | ;; "!pref.hokkaido.jp" | ||
| 76 | ((and (eq modifier t) | ||
| 77 | (string= domain entry)) | ||
| 78 | (setq allowedp t)) | ||
| 79 | ;; "*.ar" | ||
| 80 | ((and (numberp modifier) | ||
| 81 | (= length modifier) | ||
| 82 | (string= entry upper-domain)) | ||
| 83 | (setq allowedp nil)))) | ||
| 84 | allowedp)) | ||
| 85 | |||
| 86 | ;; Tests: | ||
| 87 | |||
| 88 | ;; (url-domsuf-cookie-allowed-p "com") => nil | ||
| 89 | ;; (url-domsuf-cookie-allowed-p "foo.bar.ar") => t | ||
| 90 | ;; (url-domsuf-cookie-allowed-p "bar.ar") => nil | ||
| 91 | ;; (url-domsuf-cookie-allowed-p "co.uk") => nil | ||
| 92 | ;; (url-domsuf-cookie-allowed-p "foo.bar.hokkaido.jo") => t | ||
| 93 | ;; (url-domsuf-cookie-allowed-p "bar.hokkaido.jp") => nil | ||
| 94 | ;; (url-domsuf-cookie-allowed-p "pref.hokkaido.jp") => t | ||
| 95 | |||
| 96 | (provide 'url-domsuf) | ||
| 97 | |||
| 98 | ;;; url-domsuf.el ends here | ||
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index 848eb66e54b..d12bd5447fa 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el | |||
| @@ -330,8 +330,7 @@ forbidden in URL encoding." | |||
| 330 | " ") | 330 | " ") |
| 331 | (t (byte-to-string code)))) | 331 | (t (byte-to-string code)))) |
| 332 | str (substring str (match-end 0))))) | 332 | str (substring str (match-end 0))))) |
| 333 | (setq tmp (concat tmp str)) | 333 | (concat tmp str))) |
| 334 | tmp)) | ||
| 335 | 334 | ||
| 336 | (defconst url-unreserved-chars | 335 | (defconst url-unreserved-chars |
| 337 | '( | 336 | '( |
diff --git a/lisp/url/url.el b/lisp/url/url.el index 5ced789e4e4..f3ef553bbce 100644 --- a/lisp/url/url.el +++ b/lisp/url/url.el | |||
| @@ -149,7 +149,9 @@ take effect. | |||
| 149 | 149 | ||
| 150 | If SILENT, then don't message progress reports and the like. | 150 | If SILENT, then don't message progress reports and the like. |
| 151 | If INHIBIT-COOKIES, cookies will neither be stored nor sent to | 151 | If INHIBIT-COOKIES, cookies will neither be stored nor sent to |
| 152 | the server." | 152 | the server. |
| 153 | If URL is a multibyte string, it will be encoded as utf-8 and | ||
| 154 | URL-encoded before it's used." | ||
| 153 | ;;; XXX: There is code in Emacs that does dynamic binding | 155 | ;;; XXX: There is code in Emacs that does dynamic binding |
| 154 | ;;; of the following variables around url-retrieve: | 156 | ;;; of the following variables around url-retrieve: |
| 155 | ;;; url-standalone-mode, url-gateway-unplugged, w3-honor-stylesheets, | 157 | ;;; url-standalone-mode, url-gateway-unplugged, w3-honor-stylesheets, |
| @@ -171,11 +173,16 @@ the list of events, as described in the docstring of `url-retrieve'. | |||
| 171 | 173 | ||
| 172 | If SILENT, don't message progress reports and the like. | 174 | If SILENT, don't message progress reports and the like. |
| 173 | If INHIBIT-COOKIES, cookies will neither be stored nor sent to | 175 | If INHIBIT-COOKIES, cookies will neither be stored nor sent to |
| 174 | the server." | 176 | the server. |
| 177 | If URL is a multibyte string, it will be encoded as utf-8 and | ||
| 178 | URL-encoded before it's used." | ||
| 175 | (url-do-setup) | 179 | (url-do-setup) |
| 176 | (url-gc-dead-buffers) | 180 | (url-gc-dead-buffers) |
| 177 | (if (stringp url) | 181 | (if (stringp url) |
| 178 | (set-text-properties 0 (length url) nil url)) | 182 | (set-text-properties 0 (length url) nil url)) |
| 183 | (when (multibyte-string-p url) | ||
| 184 | (let ((url-unreserved-chars (append '(?: ?/) url-unreserved-chars))) | ||
| 185 | (setq url (url-hexify-string url)))) | ||
| 179 | (if (not (vectorp url)) | 186 | (if (not (vectorp url)) |
| 180 | (setq url (url-generic-parse-url url))) | 187 | (setq url (url-generic-parse-url url))) |
| 181 | (if (not (functionp callback)) | 188 | (if (not (functionp callback)) |