Skip to content

Commit 0507e0b

Browse files
committed
(PDB-5161) Remove maybe-strip-escape-quotes and dotted-query-to-path
...now that they've been completely replaced by parse-field.
1 parent 83073dd commit 0507e0b

File tree

3 files changed

+13
-74
lines changed

3 files changed

+13
-74
lines changed

src/puppetlabs/puppetdb/query_eng/parse.clj

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -163,40 +163,4 @@
163163
[names]
164164
(str/join \. (map quote-path-name-for-field-str names)))
165165

166-
(defn maybe-strip-escaped-quotes
167-
[s]
168-
(if (and (> (count s) 1)
169-
(str/starts-with? s "\"")
170-
(str/ends-with? s "\""))
171-
(subs s 1 (dec (count s)))
172-
s))
173-
174-
(defn- handle-quoted-path-segment
175-
[v]
176-
(loop [result []
177-
[s & splits] v]
178-
(let [s-len (count s)]
179-
(if (and (str/ends-with? s "\"")
180-
(not (= s-len 1))
181-
(or (<= s-len 2) (not (= (nth s (- s-len 2)) \\))))
182-
[(str/join "." (conj result s)) splits]
183-
(recur (conj result s) splits)))))
184-
185-
(defn dotted-query->path
186-
[string]
187-
(loop [[s & splits :as v] (str/split string #"\.")
188-
result []]
189-
(if (nil? s)
190-
result
191-
(let [s-len (count s)]
192-
(if (and (str/starts-with? s "\"")
193-
(or (= s-len 1)
194-
(or (not (str/ends-with? s "\""))
195-
(and (str/ends-with? s "\"")
196-
(>= s-len 2)
197-
(= (nth s (- s-len 2)) \\)))))
198-
(let [[x xs] (handle-quoted-path-segment v)]
199-
(recur xs (conj result x)))
200-
(recur splits (conj result s)))))))
201-
202166
(set! *warn-on-reflection* warn-on-reflection-orig)

test/puppetlabs/puppetdb/pql/parser_test.clj

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
[clojure.string :as str]
44
[clojure.test :refer :all]
55
[instaparse.core :as insta]
6-
[puppetlabs.puppetdb.pql :refer [parse]]
7-
[puppetlabs.puppetdb.query-eng.parse :refer [dotted-query->path]]))
6+
[puppetlabs.puppetdb.pql :refer [parse]]))
87

98
;; These tests are ordered the same as in the EBNF file, so one can
109
;; develop the expressions and tests side-by-side.
@@ -564,18 +563,18 @@
564563
""))
565564

566565
(testing "field"
567-
(are [in] (= (parse in :start :field)
568-
(vec (concat [:field] (dotted-query->path in))))
569-
"certname"
570-
"value"
571-
"field_underscore"
572-
"facts.operatingsystem.κόσμε"
573-
"facts.\"quoted field\".foo"
574-
"facts.\"field.with.dot\".foo"
575-
"facts.\"field-with-dash\".foo"
576-
"trusted.authenticated"
577-
"parameters.😁"
578-
"latest_report?")
566+
(doseq [[field expected]
567+
[["certname" [:field "certname"]]
568+
["value" [:field "value"]]
569+
["field_underscore" [:field "field_underscore"]]
570+
["facts.operatingsystem.κόσμε" [:field "facts" "operatingsystem" "κόσμε"]]
571+
["facts.\"quoted field\".foo" [:field "facts" "\"quoted field\"" "foo"]]
572+
["facts.\"field.with.dot\".foo" [:field "facts" "\"field.with.dot\"" "foo"]]
573+
["facts.\"field-with-dash\".foo" [:field "facts" "\"field-with-dash\"" "foo"]]
574+
["trusted.authenticated" [:field "trusted" "authenticated"]]
575+
["parameters.😁" [:field "parameters" "😁"]]
576+
["latest_report?" [:field "latest_report?"]]]]
577+
(is (= expected (parse field :start :field))))
579578

580579
(are [in] (insta/failure? (insta/parse parse in :start :field))
581580
"'asdf'"

test/puppetlabs/puppetdb/query_eng/parse_test.clj

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,3 @@
114114
(is (= "x.y" (parse/path-names->field-str ["x" "y"])))
115115
(is (= "x.y z" (parse/path-names->field-str ["x" "y z"])))
116116
(is (= "x.\"y.z\"" (parse/path-names->field-str ["x" "y.z"]))))
117-
118-
(deftest dotted-query-to-path
119-
(testing "vanilla dotted path"
120-
(is (= (parse/dotted-query->path "facts.foo.bar")
121-
["facts" "foo" "bar"])))
122-
(testing "dot inside quotes"
123-
(is (= (parse/dotted-query->path "facts.\"foo.bar\".baz")
124-
["facts" "\"foo.bar\"" "baz"]))
125-
(is (= (parse/dotted-query->path "facts.\"foo.baz.bar\".baz")
126-
["facts" "\"foo.baz.bar\"" "baz"]))
127-
(is (= (parse/dotted-query->path "facts.\"foo.bar\".\"baz.bar\"")
128-
["facts" "\"foo.bar\"" "\"baz.bar\""])))
129-
(testing "consecutive dots"
130-
(is (= (parse/dotted-query->path "facts.\"foo..bar\"")
131-
["facts" "\"foo..bar\""])))
132-
(testing "path with quote in middle"
133-
(is (= (parse/dotted-query->path "facts.foo\"bar.baz")
134-
["facts" "foo\"bar" "baz"])))
135-
(testing "path containing escaped quote"
136-
(is (= (parse/dotted-query->path "\"fo\\\".o\"")
137-
["\"fo\\\".o\""])))
138-
(testing "dotted path with quote"
139-
(is (= (parse/dotted-query->path "facts.\"foo.bar\"baz\".biz")
140-
["facts" "\"foo.bar\"baz\"" "biz"]))))

0 commit comments

Comments
 (0)