From ee68b062ccb808f4b4faf434b8db163aca15ecc6 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 23 Mar 2016 14:43:36 -0700 Subject: [PATCH] correct conditional logic in `splice` --- pollen/private/splice.rkt | 17 +++++++++++------ pollen/private/ts.rktd | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pollen/private/splice.rkt b/pollen/private/splice.rkt index 20bbb36..0d4b77d 100644 --- a/pollen/private/splice.rkt +++ b/pollen/private/splice.rkt @@ -16,12 +16,16 @@ (define (splice x [splicing-tag splice-signal-tag]) ; (listof txexpr-elements?) . -> . (listof txexpr-elements?)) (define spliceable? (λ(x) (and (pair? x) (eq? (car x) splicing-tag)))) - (define not-null-string? (λ(x) (not (and (string? x) (= (string-length x) 0))))) + (define not-null-string? (λ(x) (not (and (string? x) (zero? (string-length x)))))) (let loop ([x x]) - (if (and (list? x) (not (attrs? x))) ; don't splice null strings inside attrs - (apply append (map (λ(x) ((if (spliceable? x) - cdr - list) (loop x))) (filter not-null-string? x))) + (if (list? x) ; don't exclude `attrs?` here, because it will exclude valid splice input like '((@ "foo")) + (apply append (map (λ(x) (let ([proc (if (spliceable? x) ; drop the splice-signal from front with `cdr` + cdr + list)] + [x (if (not (attrs? x)) ; don't recur on attributes, so null strings are not spliced within + (loop x) + x)]) + (proc x))) (filter not-null-string? x))) x))) (module+ test @@ -32,7 +36,8 @@ '(1 2 3 (div 4 5) 6 7)) (check-equal? (splice `((,splice-signal-tag "foo" "" "bar"))) '("foo" "bar")) (check-equal? (splice null) null) - (check-equal? (splice '(a ((href "")(foo "bar")) "zam")) '(a ((href "")(foo "bar")) "zam"))) + (check-equal? (splice '(a ((href "")(foo "bar")) "zam")) '(a ((href "")(foo "bar")) "zam")) + (check-equal? (splice `((,splice-signal-tag "str"))) '("str"))) (define (strip-empty-attrs x) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index 3e13229..121e4cf 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1457724166 +1458769416