diff options
| author | Andreas Schwab | 2014-06-22 23:14:43 +0200 |
|---|---|---|
| committer | Andreas Schwab | 2014-06-22 23:14:43 +0200 |
| commit | f76c98dd13ae5ab69d014d2459b3ed8eaf82c2f8 (patch) | |
| tree | 99418fb95b681581063ad81f700a00ba8b4c502d | |
| parent | f3953a24ea8b800170bde3db98565f2040b2f915 (diff) | |
| download | emacs-f76c98dd13ae5ab69d014d2459b3ed8eaf82c2f8.tar.gz emacs-f76c98dd13ae5ab69d014d2459b3ed8eaf82c2f8.zip | |
* html2text.el (html2text-get-attr): Rewrite to handle spaces in quoted
attribute values. (Bug#17834)
| -rw-r--r-- | lisp/gnus/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/gnus/html2text.el | 80 |
2 files changed, 19 insertions, 66 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index c9a23e47e6c..4ad3a6de63e 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-06-22 Andreas Schwab <schwab@linux-m68k.org> | ||
| 2 | |||
| 3 | * html2text.el (html2text-get-attr): Rewrite to handle spaces in quoted | ||
| 4 | attribute values. (Bug#17834) | ||
| 5 | |||
| 1 | 2014-05-28 Andreas Schwab <schwab@linux-m68k.org> | 6 | 2014-05-28 Andreas Schwab <schwab@linux-m68k.org> |
| 2 | 7 | ||
| 3 | * html2text.el (html2text-get-attr): Fix typo when splitting value from | 8 | * html2text.el (html2text-get-attr): Fix typo when splitting value from |
diff --git a/lisp/gnus/html2text.el b/lisp/gnus/html2text.el index 78cecd92356..22ee1c3921e 100644 --- a/lisp/gnus/html2text.el +++ b/lisp/gnus/html2text.el | |||
| @@ -179,72 +179,20 @@ formatting, and then moved afterward.") | |||
| 179 | 179 | ||
| 180 | (defun html2text-get-attr (p1 p2) | 180 | (defun html2text-get-attr (p1 p2) |
| 181 | (goto-char p1) | 181 | (goto-char p1) |
| 182 | (re-search-forward " +[^ ]" p2 t) | 182 | (re-search-forward "\\s-+" p2 t) |
| 183 | (let* ((attr-string (buffer-substring-no-properties (1- (point)) (1- p2))) | 183 | (let (attr-list) |
| 184 | (tmp-list (split-string attr-string)) | 184 | (while (re-search-forward "[-a-z0-9._]+" p2 t) |
| 185 | (attr-list) | 185 | (setq attr-list |
| 186 | (counter 0) | 186 | (cons |
| 187 | (prev (car tmp-list)) | 187 | (list (match-string 0) |
| 188 | (this (nth 1 tmp-list)) | 188 | (when (looking-at "\\s-*=") |
| 189 | (next (nth 2 tmp-list)) | 189 | (goto-char (match-end 0)) |
| 190 | (index 1)) | 190 | (skip-chars-forward "[:space:]") |
| 191 | 191 | (when (or (looking-at "\"[^\"]*\"\\|'[^']*'") | |
| 192 | (cond | 192 | (looking-at "[-a-z0-9._:]+")) |
| 193 | ;; size=3 | 193 | (goto-char (match-end 0)) |
| 194 | ((string-match "[^ ]=[^ ]" prev) | 194 | (match-string 0)))) |
| 195 | (let ((attr (nth 0 (split-string prev "="))) | 195 | attr-list))) |
| 196 | (value (substring prev (1+ (string-match "=" prev))))) | ||
| 197 | (setq attr-list (cons (list attr value) attr-list)))) | ||
| 198 | ;; size= 3 | ||
| 199 | ((string-match "[^ ]=\\'" prev) | ||
| 200 | (setq attr-list (cons (list (substring prev 0 -1) this) attr-list)))) | ||
| 201 | |||
| 202 | (while (< index (length tmp-list)) | ||
| 203 | (cond | ||
| 204 | ;; size=3 | ||
| 205 | ((string-match "[^ ]=[^ ]" this) | ||
| 206 | (let ((attr (nth 0 (split-string this "="))) | ||
| 207 | (value (substring this (1+ (string-match "=" this))))) | ||
| 208 | (setq attr-list (cons (list attr value) attr-list)))) | ||
| 209 | ;; size =3 | ||
| 210 | ((string-match "\\`=[^ ]" this) | ||
| 211 | (setq attr-list (cons (list prev (substring this 1)) attr-list))) | ||
| 212 | ;; size= 3 | ||
| 213 | ((string-match "[^ ]=\\'" this) | ||
| 214 | (setq attr-list (cons (list (substring this 0 -1) next) attr-list))) | ||
| 215 | ;; size = 3 | ||
| 216 | ((string= "=" this) | ||
| 217 | (setq attr-list (cons (list prev next) attr-list)))) | ||
| 218 | (setq index (1+ index)) | ||
| 219 | (setq prev this) | ||
| 220 | (setq this next) | ||
| 221 | (setq next (nth (1+ index) tmp-list))) | ||
| 222 | ;; | ||
| 223 | ;; Tags with no accompanying "=" i.e. value=nil | ||
| 224 | ;; | ||
| 225 | (setq prev (car tmp-list)) | ||
| 226 | (setq this (nth 1 tmp-list)) | ||
| 227 | (setq next (nth 2 tmp-list)) | ||
| 228 | (setq index 1) | ||
| 229 | |||
| 230 | (when (and (not (string-match "=" prev)) | ||
| 231 | (not (string= (substring this 0 1) "="))) | ||
| 232 | (setq attr-list (cons (list prev nil) attr-list))) | ||
| 233 | (while (< index (1- (length tmp-list))) | ||
| 234 | (when (and (not (string-match "=" this)) | ||
| 235 | (not (or (string= (substring next 0 1) "=") | ||
| 236 | (string= (substring prev -1) "=")))) | ||
| 237 | (setq attr-list (cons (list this nil) attr-list))) | ||
| 238 | (setq index (1+ index)) | ||
| 239 | (setq prev this) | ||
| 240 | (setq this next) | ||
| 241 | (setq next (nth (1+ index) tmp-list))) | ||
| 242 | |||
| 243 | (when (and this | ||
| 244 | (not (string-match "=" this)) | ||
| 245 | (not (string= (substring prev -1) "="))) | ||
| 246 | (setq attr-list (cons (list this nil) attr-list))) | ||
| 247 | ;; return - value | ||
| 248 | attr-list)) | 196 | attr-list)) |
| 249 | 197 | ||
| 250 | ;; | 198 | ;; |