Skip to content
Snippets Groups Projects
Unverified Commit 9fb81595 authored by Jeff Evans's avatar Jeff Evans Committed by GitHub
Browse files

Trim whitespace around commas in schema filtering code (#19949)

* Trim whitespace around commas in schema filtering code

Change impl of `schema-pattern->re-pattern` so that strings are trimmed before being joined on `|`

Add test to confirm
parent 2911c4b9
No related branches found
No related tags found
No related merge requests found
......@@ -7,16 +7,18 @@
"Converts a schema pattern, as entered in the UI, into regex pattern suitable to be passed into [[re-pattern]]. The
conversion that happens is from commas into pipes (disjunction), and wildcard characters (`*`) into greedy wildcard
matchers (`.*`). These only occur if those characters are not preceded by a backslash, which serves as an escape
character for purposes of this conversion.
character for purposes of this conversion. Any whitespace before and after commas is trimmed.
Examples:
a,b => a|b
test* => test.*
foo*,*bar => foo.*|.*bar
foo , ba*r , baz => foo|ba.*r|baz
crazy\\*schema => crazy\\*schema"
^Pattern [schema-pattern]
(re-pattern (-> (str/replace schema-pattern #"(^|[^\\\\])\*" "$1.*")
(str/replace #"(^|[^\\\\])," "$1|"))))
^Pattern [^String schema-pattern]
(re-pattern (->> (str/split schema-pattern #",")
(map (comp #(str/replace % #"(^|[^\\\\])\*" "$1.*") str/trim))
(str/join "|"))))
(defn- schema-patterns->filter-fn*
[inclusion-patterns exclusion-patterns]
......
......@@ -16,7 +16,8 @@
["inclusion filter with commas and wildcards (include)" true "foo" "bar,f*,baz" ""]
["inclusion filter with commas and wildcards (exclude)" false "ban" "bar,f*,baz" ""]
["exclusion filter with commas and wildcards (include)" true "foo" "" "ba*,fob"]
["exclusion filter with commas and wildcards (exclude)" false "foo" "" "bar,baz,fo*"]]]
["exclusion filter with commas and wildcards (exclude)" false "foo" "" "bar,baz,fo*"]
["multiple inclusion with whitespace trimming" true "bar" " foo , bar \n , \nbaz " ""]]]
(t/testing (str "include-schema? works as expected for " test-kind)
(t/is (= expect-match? (driver.s/include-schema? inclusion-filters exclusion-filters schema-name))))
(t/testing "include-schema? throws an exception if both patterns are specified"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment