;; input (3.1, 3.3)
;; - if line-length is set, error on input exceeding the limit (3.1)
;; - reject characters outside base encoding (3.3, also section 12)
- (let ((splitstr (split-string str "[\n\r \t]+" t)))
+ ;;
+ ;; RFC 5322 section 2.2.3 consideration:
+ ;; Because base 64-encoded strings can appear in long header fields, remove
+ ;; folding whitespace while still observing the RFC 4648 decisions above.
+ (let ((splitstr (split-string str "[ \t]*[\r\n]+[ \t]?" t)))
(when (and reject-newlines (> (length splitstr) 1))
(error "Invalid Base64 string"))
(dolist (substr splitstr)
(should (equal "Zg==" (gnus-base64-repad "Zg")))
(should (equal "Zg==" (gnus-base64-repad "Zg====")))
- (should (equal (gnus-base64-repad " ") ""))
- (should (equal (gnus-base64-repad "Zg== ") "Zg=="))
+ (should-error (gnus-base64-repad " ")
+ :type 'error)
+ (should-error (gnus-base64-repad "Zg== ")
+ :type 'error)
(should-error (gnus-base64-repad "Z?\x00g==")
:type 'error)
;; line-length
(should-error (gnus-base64-repad "Zm9v\r\nYmFy" t)
:type 'error)
(should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9vYmFy" t)))
- (should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9v\r\nYmFy" nil)))
- (should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9v\r\nYmFy\n" nil)))
- (should (equal (gnus-base64-repad "Zm9v\r\n YmFy\r\n" nil) "Zm9vYmFy"))
+ (should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9v\r\nYmFy")))
+ (should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9v\r\nYmFy\n")))
+ (should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9v\r\n YmFy\r\n")))
+ (should (equal "Zm9vYmFy" (gnus-base64-repad "Zm9v \r\n\tYmFy")))
(should-error (gnus-base64-repad "Zm9v\r\nYmFy" nil 3)
:type 'error))