From e9f9b6a303450c28e1c63db695d7d6e7cb48595f Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 8 Nov 2014 19:44:38 -0500 Subject: [PATCH] Check for empty version number --- TODO.md | 2 -- src/main.rkt | 16 ++++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 26a7d6c..ceecfec 100644 --- a/TODO.md +++ b/TODO.md @@ -13,8 +13,6 @@ you should be able to specify git repos over http/https you should be able to specify subdirs in git repos you should check the existence of repos/github repos/urls/etc via XHR -don't let people enter blank version numbers - Much more input validation is needed ## Design possibilities diff --git a/src/main.rkt b/src/main.rkt index ac7d0db..0f48e34 100644 --- a/src/main.rkt +++ b/src/main.rkt @@ -908,12 +908,16 @@ ;; Right up there with "parse error". draft))] ["add_version" - (if (assoc new_version (draft-package-versions draft)) - (package-form (format "Could not add version ~a, as it already exists." new_version) - draft) - (package-form #f (struct-copy draft-package draft - [versions (cons (list new_version default-empty-source-url) - (draft-package-versions draft))])))] + (cond + [(equal? (string-trim new_version) "") + (package-form "Please enter a version number to add." draft)] + [(assoc new_version (draft-package-versions draft)) + (package-form (format "Could not add version ~a, as it already exists." new_version) + draft)] + [else + (package-form #f (struct-copy draft-package draft + [versions (cons (list new_version default-empty-source-url) + (draft-package-versions draft))]))])] [(regexp #px"^version__(.*)__delete$" (list _ version)) (package-form #f (struct-copy draft-package draft [versions (filter (lambda (v)