Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite: check for base64 for text content in blob #1472

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/sources/sqlite/sqlite.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

(in-package :pgloader.source.sqlite)

(in-package :pgloader.source.sqlite)

(declaim (inline has-base64-sequence-p))

;;; Return the decoded value of a base64 string, ignoring errors.
;;; Returns nil if the string doesn't contain a valid base64 string.
;;;
(defun has-base64-value-p (string)
(ignore-errors
(base64:base64-string-to-string string)))

;;; Map a function to each row extracted from SQLite
;;;
(declaim (inline parse-value))
Expand All @@ -20,10 +31,16 @@
(babel:octets-to-string value :encoding encoding))

((and (string-equal "bytea" pgsql-type)
(has-base64-value-p value)
(stringp value))
;; we expected bytes and got a string instead, must be base64 encoded
;; we expected bytes and got a be base64 encoded, string instead
(base64:base64-string-to-usb8-array value))

((and (string-equal "bytea" pgsql-type)
(stringp value))
;; we expected bytes and got a string instead, convert it to octets
(babel:string-to-octets value :encoding :utf-8))

;; default case, just use what's been given to us
(t value)))

Expand Down