Skip to content

Commit ba26724

Browse files
swannodettequoll
andauthored
CLJS-3370: improved uuid regex to only accept hex characters (#166)
Co-authored-by: Paula Gearon <[email protected]>
1 parent 8528937 commit ba26724

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12062,7 +12062,7 @@ reduces them without incurring seq initialization"
1206212062
(throw (js/Error. (parsing-err s)))))
1206312063

1206412064
(def ^:private uuid-regex
12065-
#"^[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]-[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]-[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]-[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]-[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z]$")
12065+
#"^[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$")
1206612066

1206712067
(defn parse-uuid
1206812068
"Parse a string representing a UUID and return a UUID instance,

src/test/cljs/cljs/parse_test.cljs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@
8080
(are [s] ;; throw on invalid type (not string)
8181
(try (parse-uuid s) (is false) (catch :default _ (is true)))
8282
123
83-
nil))
83+
nil)
84+
;; parse the nil uuid
85+
(is (parse-uuid "00000000-0000-0000-0000-000000000000"))
86+
;; parse a version 1 UUID
87+
(is (parse-uuid "123e4567-e89b-12d3-a456-426614174000"))
88+
;; parse a version 2 UUID
89+
(is (parse-uuid "123e4567-e89b-22d3-a456-426614174000"))
90+
;; ensure that bad characters are invalid
91+
(is (nil? (parse-uuid "123e4567-eg9b-12d3-a456-426614174000"))))
8492

8593
(deftest test-parse-boolean
8694
(is (identical? true (parse-boolean "true")))

0 commit comments

Comments
 (0)