Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix escaping #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/axel_f/lexer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
(defn- escape-char? [{::keys [type]}]
(= type ::escaped))

(defn- escape-str [args]
(string/replace (apply str args) #"\\(.)" "$1"))

(defmulti read-next* (fn [[e & _]]
(cond
(whitespace? e) ::whitespace
Expand Down Expand Up @@ -113,7 +110,7 @@
(if (and (= v literal-t)
(not (escape-char? (last acc))))
[{::type ::string
::value (->> acc (map ::v) escape-str)
::value (apply str (map ::v acc))
::begin {::line line
::col col}
::end {::line l
Expand Down Expand Up @@ -226,7 +223,7 @@
(not (escape-char? (last acc))))
(let [{l' ::l c' ::c} (last acc)]
[{::type ::symbol
::value (->> acc (map ::v) escape-str)
::value (apply str (map ::v acc))
::begin {::line l
::col c}
::end {::line l'
Expand Down
6 changes: 3 additions & 3 deletions test/axel_f/functions_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
(t/deftest regexextract-function-test
(t/testing "REGEXEXTRACT function"
(t/is (= "826.25"
((af/compile "REGEXEXTRACT('The price today is $826.25', '[0-9]*\\\\.[0-9]+[0-9]+')"))))
((af/compile "REGEXEXTRACT('The price today is $826.25', '[0-9]*\\.[0-9]+[0-9]+')"))))

(t/is (= "Content"
((af/compile "REGEXEXTRACT('(Content) between brackets', '\\(([A-Za-z]+)\\)')"))))
Expand All @@ -358,10 +358,10 @@
(t/deftest regexreplace-function-test
(t/testing "REGEXREPLACE function"
(t/is (= "The price today is $0.00"
((af/compile "REGEXREPLACE('The price today is $826.25', '[0-9]*\\\\.[0-9]+[0-9]+', '0.00')"))))
((af/compile "REGEXREPLACE('The price today is $826.25', '[0-9]*\\.[0-9]+[0-9]+', '0.00')"))))

(t/is (= "Word between brackets"
((af/compile "REGEXREPLACE('(Content) between brackets', '\\\\(([A-Za-z]+)\\\\)', 'Word')"))))
((af/compile "REGEXREPLACE('(Content) between brackets', '\\(([A-Za-z]+)\\)', 'Word')"))))

(t/is (= "FOO"
((af/compile "REGEXREPLACE('FOO', '[a-z]+', 'OOF')"))))))
Expand Down
25 changes: 12 additions & 13 deletions test/axel_f/issue_35_test.cljc
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
(ns axel-f.issue-35-test
(:require #?(:clj [clojure.test :as t]
:cljs [cljs.test :as t :include-macros true])
[axel-f.excel :as af]
[clojure.string :as string]))
[axel-f.excel :as af]))

(t/deftest object-references-could-be-anything

(t/testing "fields with unicode symbols inside"

(t/are [x] (= 1 ((af/compile x) {(keyword (string/replace x #"\\" "")) 1}))
(t/are [x] (= 1 ((af/compile (str ".'" x "'")) {(keyword x) 1}))
"ꙮ"
"fooꙮbar"
"foo\\-bar"))
"foo-bar"))

(t/testing "quoted fields with operators inside"

(t/are [x] (= 1 ((af/compile x) {(keyword (string/replace x #"\\" "")) 1}))
"foo\\/bar"
"foo\\+"
"foo\\*bar"
"foo\\>bar"
"foo\\ \\>\\ bar"
"foo\\^bar"
"foo\\%bar"
"foo\\&bar"))
(t/are [x] (= 1 ((af/compile (str ".'" x "'")) {(keyword x) 1}))
"foo/bar"
"foo+"
"foo*bar"
"foo>bar"
"foo > bar"
"foo^bar"
"foo%bar"
"foo&bar"))

#_(t/testing "fields with special symbols throw an error without quoting"

Expand Down