From 91e639390fc1ea42278c06d6f3f2d0e70bc2ebcd Mon Sep 17 00:00:00 2001 From: Wanderson Ferreira Date: Thu, 8 Dec 2022 08:25:11 -0300 Subject: [PATCH] do not include empty aliases in the compressed scopes --- src/scopula/core.clj | 3 ++- test/scopula/core_test.clj | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scopula/core.clj b/src/scopula/core.clj index ba4501f..ed460b3 100644 --- a/src/scopula/core.clj +++ b/src/scopula/core.clj @@ -471,7 +471,8 @@ (defn- scopes-compress-first [scopes sorted-aliases] (let [[alias-name sd] (first (keep (fn [[alias-name ss]] - (when (scopes-subset? ss scopes) + (when (and (scopes-subset? ss scopes) + (seq ss)) (try [alias-name (scope-difference scopes ss)] (catch Exception _ nil)))) sorted-aliases))] diff --git a/test/scopula/core_test.clj b/test/scopula/core_test.clj index 00b0491..346fb10 100644 --- a/test/scopula/core_test.clj +++ b/test/scopula/core_test.clj @@ -370,6 +370,12 @@ (sut/scopes-compress #{"foo" "bar" "baz" "x"} {"+admin" #{"foo" "bar"} "+baz" #{"baz"}}))) + (is (= #{"+admin" "+baz" "x"} + (sut/scopes-compress #{"foo" "bar" "baz" "x"} + {"+admin" #{"foo" "bar"} + "+baz" #{"baz"} + "+foo" #{}})) + "Make sure if the alias dictionary have an empty entry, the alias-name will not be included in the compressed-scopes") (is (= #{"+admin" "+baz" "baz:write" "x"} (sut/scopes-compress #{"foo" "bar" "baz" "x"}