From 47c2b8135d4babb2780a1529c70f0353b3c85222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E7=AB=BF=E9=92=93=E9=B1=BC=E5=B9=B2?= <46661603+PokIsemaine@users.noreply.github.com> Date: Fri, 19 May 2023 16:25:30 +0800 Subject: [PATCH] fix: removeFilteredNamedGroupingPolicy "" filtered (#62) * fix: removeFilteredNamedGroupingPolicy "" filtered * refactor: removeFilteredPolicy * refactor: removeFilteredPolicy again * fix: update node-version * refactor: removeFilteredPolicy 2 --- .github/workflows/maven-ci.yml | 2 +- src/main/java/org/casbin/adapter/JDBCBaseAdapter.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 6242056..bfba7ab 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -71,7 +71,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: 16 + node-version: 18 - name: Sematic Release run: | diff --git a/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java b/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java index 45acb58..008a6cd 100644 --- a/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java +++ b/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java @@ -473,14 +473,16 @@ public void removeFilteredPolicy(String sec, String ptype, int fieldIndex, Strin } String sql = renderActualSql("DELETE FROM casbin_rule WHERE ptype = ?"); int columnIndex = fieldIndex; - for (int i = 0; i < values.size(); i++) { + for (int i = 0; i < values.size(); i++, columnIndex++) { + if (Objects.equals(values.get(i), "")) continue; sql = String.format("%s%s%s%s", sql, " AND v", columnIndex, " = ?"); - columnIndex++; } try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, ptype); - for (int j = 0; j < values.size(); j++) { - ps.setString(j + 2, values.get(j)); + int index = 2; + for (String value : values) { + if (Objects.equals(value, "")) continue; + ps.setString(index++, value); } int rows = ps.executeUpdate(); if (rows < 1 && removePolicyFailed) {