Fix an error when storing UTF-8 data to DBI session store.

This commit is contained in:
Eitaro Fukamachi 2015-11-19 18:05:04 +09:00
parent 114b513c89
commit 4f07c50b6c
2 changed files with 10 additions and 4 deletions

View file

@ -10,6 +10,7 @@
:depends-on (:lack-middleware-session :depends-on (:lack-middleware-session
:dbi :dbi
:marshal :marshal
:trivial-utf-8
:cl-base64) :cl-base64)
:components ((:file "src/middleware/session/store/dbi")) :components ((:file "src/middleware/session/store/dbi"))
:in-order-to ((test-op (test-op t-lack-session-store-dbi)))) :in-order-to ((test-op (test-op t-lack-session-store-dbi))))

View file

@ -7,8 +7,11 @@
:marshal :marshal
:unmarshal) :unmarshal)
(:import-from :cl-base64 (:import-from :cl-base64
:base64-string-to-string :base64-string-to-usb8-array
:string-to-base64-string) :usb8-array-to-base64-string)
(:import-from :trivial-utf-8
:string-to-utf-8-bytes
:utf-8-bytes-to-string)
(:export :dbi-store (:export :dbi-store
:make-dbi-store :make-dbi-store
:fetch-session :fetch-session
@ -19,9 +22,11 @@
(defstruct (dbi-store (:include store)) (defstruct (dbi-store (:include store))
(connector nil :type function) (connector nil :type function)
(serializer (lambda (data) (serializer (lambda (data)
(string-to-base64-string (prin1-to-string (marshal data))))) (usb8-array-to-base64-string
(string-to-utf-8-bytes (prin1-to-string (marshal data))))))
(deserializer (lambda (data) (deserializer (lambda (data)
(unmarshal (read-from-string (base64-string-to-string data))))) (unmarshal (read-from-string
(utf-8-bytes-to-string (base64-string-to-usb8-array data))))))
(table-name "sessions")) (table-name "sessions"))
(defmethod fetch-session ((store dbi-store) sid) (defmethod fetch-session ((store dbi-store) sid)