branch: externals/triples
commit 4be631ae9531d8ea729a1de42da79127d04f2fae
Author: Andrew Hyatt <[email protected]>
Commit: Andrew Hyatt <[email protected]>
Fix inescapification that can happen in strings
We want to be able to store something and have it be retrieved exactly the
same.
To that end, let's no longer have on control character escapification.
Also,
stop our incorrect string munging in favor of simply reading values in the
majority of situations.
---
triples-test.el | 10 ++++++++++
triples.el | 12 +++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/triples-test.el b/triples-test.el
index 1f1fbbe541..c0a073fd98 100644
--- a/triples-test.el
+++ b/triples-test.el
@@ -296,6 +296,16 @@ easily debug into it.")
(should (equal '(:name ("Name"))
(triples-get-type db "foo" 'named)))))
+(ert-deftest triples-store-and-retrieve ()
+ (triples-test-with-temp-db
+ (triples-add-schema db 'text '(text :base/unique t))
+ (let ((text "Foo\nBar\tBaz \"Quoted\" "))
+ (triples-set-type db "foo" 'text :text text)
+ (let ((retrieved (triples-get-type db "foo" 'text)))
+ (should (equal `(:text ,text) retrieved))
+ (triples-set-type db "foo" 'text retrieved)
+ (should (equal `(:text ,text) (triples-get-type db "foo" 'text)))))))
+
(ert-deftest triples-vector ()
(triples-test-with-temp-db
(triples-add-schema db 'named 'name)
diff --git a/triples.el b/triples.el
index f5092a8834..73d50223b0 100644
--- a/triples.el
+++ b/triples.el
@@ -138,7 +138,9 @@ exist at any time. Older backups are the ones that are
deleted."
This is done to have compatibility with the way emacsql stores
values. Turn a symbol into a string as well, but not a quoted
one, because sqlite cannot handle symbols."
- (let ((print-escape-control-characters t))
+ ;; Do not print control characters escaped - we want to get things out
exactly
+ ;; as we put them in.
+ (let ((print-escape-control-characters nil))
(if val
(format "%S" val)
;; Just to save a bit of space, let's use "()" instead of "null", which
is
@@ -150,13 +152,9 @@ one, because sqlite cannot handle symbols."
This imitates the way emacsql returns items, with strings
becoming either symbols, lists, or strings depending on whether
the string itself is wrapped in quotes."
- (if (and (stringp result)
- (string-prefix-p "\"" result)
- (string-suffix-p "\"" result))
- (string-remove-suffix "\"" (string-remove-prefix "\"" result))
- (if (numberp result)
+ (if (numberp result)
result
- (read result))))
+ (read result)))
(defun triples-db-insert (db subject predicate object &optional properties)
"Insert triple to DB: SUBJECT, PREDICATE, OBJECT with PROPERTIES.