Skip to content

Commit c21960d

Browse files
committed
Support ~ in dynamic string parser.
1 parent ea71fa8 commit c21960d

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Support `~` in dynamic string parser.
6+
57
## 0.86.0
68

79
- Improve agent behavior prompt to mention usage of editor_diagnostics tool. #230

src/eca/config.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,12 @@
159159
(string/replace #"\$\{file:([^}]+)\}"
160160
(fn [[_match file-path]]
161161
(try
162-
(slurp (str (if (fs/absolute? file-path)
163-
file-path
164-
(if cwd
165-
(fs/path cwd file-path)
166-
(fs/path file-path)))))
162+
(let [file-path (fs/expand-home file-path)]
163+
(slurp (str (if (fs/absolute? file-path)
164+
file-path
165+
(if cwd
166+
(fs/path cwd file-path)
167+
(fs/path file-path))))))
167168
(catch Exception _
168169
(logger/warn logger-tag "File not found when parsing string:" s)
169170
""))))

test/eca/config_test.clj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
[eca.logger :as logger]
88
[eca.secrets :as secrets]
99
[eca.test-helper :as h]
10-
[matcher-combinators.test :refer [match?]]))
10+
[matcher-combinators.test :refer [match?]]
11+
[clojure.string :as string]))
1112

1213
(h/reset-components-before-test)
1314

@@ -282,6 +283,17 @@
282283
(throw (ex-info "File not found" {}))))]
283284
(is (= "relative file content" (#'config/parse-dynamic-string "${file:test.txt}" "/tmp" {})))))
284285

286+
(testing "replaces file pattern with file content - path with ~"
287+
(with-redefs [fs/absolute? (fn [_] true)
288+
fs/path (fn [cwd file-path] (str cwd "/" file-path))
289+
fs/expand-home (fn [f]
290+
(string/replace (str f) "~" "/home/user"))
291+
slurp (fn [path]
292+
(if (= path "/home/user/foo/test.txt")
293+
"relative file content"
294+
(throw (ex-info "File not found" {}))))]
295+
(is (= "relative file content" (#'config/parse-dynamic-string "${file:~/foo/test.txt}" "/tmp" {})))))
296+
285297
(testing "replaces file pattern with empty string when file not found"
286298
(with-redefs [logger/warn (fn [& _] nil)
287299
fs/absolute? (fn [_] true)

0 commit comments

Comments
 (0)