diff --git a/txexpr/base.rkt b/txexpr/base.rkt index 74a91d4..43c10bb 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -115,11 +115,12 @@ (define+provide+safe (validate-txexpr x) (any/c . -> . txexpr?) (unless (list? x) (raise-argument-error 'validate-txexpr "tagged X-expression" x)) - (unless (symbol? (car x)) (txexpr-error "tag" "must be a symbol" (car x) x)) - (match (rest x) - [(list-rest (list (? list?) attrs ...) elems) + (match x + [(list* tag _) #:when (not (symbol? tag)) + (txexpr-error "tag" "must be a symbol" tag x)] + [(list* tag (or (? null?) (list (? list?) _ ...)) elems) (and (validate-txexpr-attrs x) (validate-txexpr-elements elems x) x)] - [(? list? elems) (and (validate-txexpr-elements elems x) x)])) + [(list* tag elems) (and (validate-txexpr-elements elems x) x)])) (define (txexpr-unsafe tag attrs elements) (cons tag (match attrs diff --git a/txexpr/test/tests.rkt b/txexpr/test/tests.rkt index a7190b1..3e66fd3 100644 --- a/txexpr/test/tests.rkt +++ b/txexpr/test/tests.rkt @@ -66,6 +66,7 @@ (check-not-exn (λ _ (validate-txexpr '(p)))) (check-not-exn (λ _ (validate-txexpr '(p "foo" "bar")))) (check-not-exn (λ _ (validate-txexpr '(p ((key "value")) "foo" "bar")))) + (check-not-exn (λ _ (validate-txexpr '(p () "foo" "bar")))) (check-not-exn (λ _ (validate-txexpr '(p 123)))) ; content is a valid-char (check-exn exn:fail? (λ _ (validate-txexpr "foo"))) ; not a list with symbol (check-exn exn:fail? (λ _ (validate-txexpr '(p "foo" "bar" ((key "value")))))) ; malformed