From 08f3f699099abd8502fc841397def973d6b27319 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Tue, 6 Feb 2018 11:02:33 +0100 Subject: [PATCH] fix strings in key map portability --- src/clj_jwt/json_key_fn.clj | 11 ++++------- test/clj_jwt/json_key_fn_test.clj | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/clj_jwt/json_key_fn.clj b/src/clj_jwt/json_key_fn.clj index 471dd7c..c33cfbf 100644 --- a/src/clj_jwt/json_key_fn.clj +++ b/src/clj_jwt/json_key_fn.clj @@ -2,16 +2,13 @@ (:require [clojure.string :as str])) -(defn write-key - [x] - (cond - (string? x) (str "\"" x "\"") - :else (name x))) +(def write-key name) (defn read-key + "don't keywordize keys with / or ." [x] - (if-let [y (re-seq #"^\"(.*)\"$" x)] - (-> y first second) + (if (re-matches #".*[/.].*" x) + x (keyword x))) diff --git a/test/clj_jwt/json_key_fn_test.clj b/test/clj_jwt/json_key_fn_test.clj index 6c5832a..76857d6 100644 --- a/test/clj_jwt/json_key_fn_test.clj +++ b/test/clj_jwt/json_key_fn_test.clj @@ -5,8 +5,8 @@ (fact "write-key should work fine." (write-key :foo) => "foo" - (write-key "foo") => "\"foo\"") + (write-key "foo") => "foo") (fact "read-key should work fine." (read-key "foo") => :foo - (read-key "\"foo\"") => "foo") + (read-key "foo/bar") => "foo/bar")