diff options
| -rw-r--r-- | lisp/net/eww.el | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 179010cf4cd..90ddd05b845 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el | |||
| @@ -1400,13 +1400,38 @@ Differences in #targets are ignored." | |||
| 1400 | (unless (plist-get status :error) | 1400 | (unless (plist-get status :error) |
| 1401 | (let* ((obj (url-generic-parse-url url)) | 1401 | (let* ((obj (url-generic-parse-url url)) |
| 1402 | (path (car (url-path-and-query obj))) | 1402 | (path (car (url-path-and-query obj))) |
| 1403 | (file (eww-make-unique-file-name (file-name-nondirectory path) | 1403 | (file (eww-make-unique-file-name |
| 1404 | eww-download-directory))) | 1404 | (eww-decode-url-file-name (file-name-nondirectory path)) |
| 1405 | eww-download-directory))) | ||
| 1405 | (goto-char (point-min)) | 1406 | (goto-char (point-min)) |
| 1406 | (re-search-forward "\r?\n\r?\n") | 1407 | (re-search-forward "\r?\n\r?\n") |
| 1407 | (write-region (point) (point-max) file) | 1408 | (write-region (point) (point-max) file) |
| 1408 | (message "Saved %s" file)))) | 1409 | (message "Saved %s" file)))) |
| 1409 | 1410 | ||
| 1411 | (defun eww-decode-url-file-name (string) | ||
| 1412 | (let* ((binary (url-unhex-string string)) | ||
| 1413 | (decoded | ||
| 1414 | (decode-coding-string | ||
| 1415 | binary | ||
| 1416 | ;; Possibly set by `universal-coding-system-argument'. | ||
| 1417 | (or coding-system-for-read | ||
| 1418 | ;; RFC 3986 says that %AB stuff is utf-8. | ||
| 1419 | (if (equal (decode-coding-string binary 'utf-8) | ||
| 1420 | '(unicode)) | ||
| 1421 | 'utf-8 | ||
| 1422 | ;; But perhaps not. | ||
| 1423 | (car (detect-coding-string binary)))))) | ||
| 1424 | (encodes (find-coding-systems-string decoded))) | ||
| 1425 | (if (or (equal encodes '(undecided)) | ||
| 1426 | (memq (or file-name-coding-system | ||
| 1427 | default-file-name-coding-system) | ||
| 1428 | encodes)) | ||
| 1429 | decoded | ||
| 1430 | ;; If we can't encode the decoded file name (due to language | ||
| 1431 | ;; environment settings), then we return the original, hexified | ||
| 1432 | ;; string. | ||
| 1433 | string))) | ||
| 1434 | |||
| 1410 | (defun eww-make-unique-file-name (file directory) | 1435 | (defun eww-make-unique-file-name (file directory) |
| 1411 | (cond | 1436 | (cond |
| 1412 | ((zerop (length file)) | 1437 | ((zerop (length file)) |