Skip to content

Commit

Permalink
Merge pull request #47 from dpsutton/master
Browse files Browse the repository at this point in the history
Guard against namespace aliases with no namespace
  • Loading branch information
alexander-yakushev authored Apr 3, 2017
2 parents 8efaee8 + 14042ff commit 26f3546
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/compliment/sources/keywords.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"Returns a list of alias-qualified double-colon keywords (like ::str/foo),
where alias has to be registered in the given namespace."
[prefix ns]
(let [[_ alias prefix] (re-matches #"::([^/]+)/(.*)" prefix)
alias-ns-name (str (resolve-namespace (symbol alias) ns))]
(for [[kw _] (keywords-table)
:when (= (namespace kw) alias-ns-name)
:when (.startsWith (name kw) prefix)]
(tagged-candidate (str "::" alias "/" (name kw))))))
(when-let [[_ alias prefix] (re-matches #"::([^/]+)/(.*)" prefix)]
(let [alias-ns-name (str (resolve-namespace (symbol alias) ns))]
(for [[kw _] (keywords-table)
:when (= (namespace kw) alias-ns-name)
:when (.startsWith (name kw) prefix)]
(tagged-candidate (str "::" alias "/" (name kw)))))))

(defn candidates
[^String prefix, ns _]
Expand Down
6 changes: 5 additions & 1 deletion test/compliment/sources/t_keywords.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
(fact "keyword candidates have a special tag"
(do (str :deprecated)
(src/candidates ":depr" *ns* nil))
=> [{:candidate ":deprecated", :type :keyword}]))
=> [{:candidate ":deprecated", :type :keyword}])

(fact "namespace aliases without namespace are handled"
(do (src/candidates "::/" *ns* nil)
=> nil)))

0 comments on commit 26f3546

Please sign in to comment.