aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2019-06-20 23:31:34 +0200
committerRicardo Wurmus <rekado@elephly.net>2019-06-20 23:31:34 +0200
commitfed15b83b0b54d17057733935eb53e94e1a2c926 (patch)
treebe1c44ccfa8eacc3224c776cc1482de2d9b131a2 /src
parentd5b827097b456100039370003899ec7ad04ac934 (diff)
downloadcuirass-fed15b83b0b54d17057733935eb53e94e1a2c926.tar
cuirass-fed15b83b0b54d17057733935eb53e94e1a2c926.tar.gz
database: query->bind-arguments: Process ^ and $ characters.
* src/cuirass/database.scm (query->bind-arguments): Handle ^ and $ characters in query strings.
Diffstat (limited to 'src')
-rw-r--r--src/cuirass/database.scm34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index f74ebdd..8db5411 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -559,16 +559,30 @@ WHERE derivation =" derivation ";"))
(define (query->bind-arguments query-string)
"Return a list of keys to query strings by parsing QUERY-STRING."
- (let ((args (append-map (lambda (token)
- (match (string-split token #\:)
- (("system" system)
- `(#:system ,system))
- (("spec" spec)
- `(#:spec ,spec))
- ((_ invalid) '()) ; ignore
- ((query)
- `(#:query ,(string-append query "-%")))))
- (string-tokenize query-string))))
+ (let ((args (append-map
+ (lambda (token)
+ (match (string-split token #\:)
+ (("system" system)
+ `(#:system ,system))
+ (("spec" spec)
+ `(#:spec ,spec))
+ ((_ invalid) '()) ; ignore
+ ((query)
+ `(#:query
+ ,(fold
+ (lambda (transform val)
+ (match transform
+ ((pred modify-true modify-false)
+ ((if (pred val) modify-true modify-false) val))))
+ query
+ ;; Process special characters ^ and $.
+ (list (list (cut string-prefix? "^" <>)
+ (cut string-drop <> 1)
+ (cut string-append "%" <>))
+ (list (cut string-suffix? "$" <>)
+ (cut string-drop-right <> 1)
+ (cut string-append <> "%"))))))))
+ (string-tokenize query-string))))
;; Normalize arguments
(fold (lambda (key acc)
(if (member key acc)