Skip to content

Commit 9a89ca4

Browse files
committed
Fix unescape-unicode edge case with multiple backslashes
1 parent 8480fe1 commit 9a89ca4

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/com/walmartlabs/lacinia/parser/common.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
(-> v
5555
;; Because of how parsing works, the string literal includes the enclosing quotes
5656
(subs 1 (dec (.length v)))
57-
(str/replace #"\\([\\\"\/bfnrt])" #(unescape-ascii (second %)))
58-
(str/replace #"\\u([A-Fa-f0-9]{4})" #(unescape-unicode (second %)))))
57+
(str/replace #"\\(\\|u[A-Fa-f0-9]{4}|[\"\/bfnrt])"
58+
#(let [s (second %)]
59+
(cond
60+
(= s "\\") "\\"
61+
(= (first s) \u) (unescape-unicode (subs s 1))
62+
:else (unescape-ascii s))))))
5963

6064
(defn ^:private indent-of
6165
[s]

test/com/walmartlabs/lacinia/parser/query_test.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@
7373
(testing "unicode"
7474
(is (= {:id "1138"
7575
:newHomePlanet "❄HOTH❄"}
76-
(args "mutation { changeHeroHomePlanet(id: \"1138\", newHomePlanet: \"\\u2744\\uff28\\uff2f\\uff34\\uff28\\u2744\") {name}}")))))
76+
(args "mutation { changeHeroHomePlanet(id: \"1138\", newHomePlanet: \"\\u2744\\uff28\\uff2f\\uff34\\uff28\\u2744\") {name}}"))))
77+
78+
(testing "not unicode"
79+
(is (= {:id "1139"
80+
:newHomePlanet "\\u2744\\uff28\\uff2f\\uff34\\uff28\\u2744"}
81+
(args "mutation { changeHeroHomePlanet(id: \"1139\", newHomePlanet: \"\\\\u2744\\\\uff28\\\\uff2f\\\\uff34\\\\uff28\\\\u2744\") {name}}")))))
7782

7883
(deftest query-reserved-word
7984
;; Use 'query', 'mutation', and 'subscription' in various unusual places.

0 commit comments

Comments
 (0)