From 45a6cc15eceddabeb1c0cae08e350fee8b165b2a Mon Sep 17 00:00:00 2001 From: Dmitry Litvintsev Date: Wed, 4 Sep 2024 12:40:55 -0500 Subject: [PATCH] bulk: check targets for empty strings Motivation: When specifying empty target the bulk proceeds to process the request instead of failing fast. Modification: Fix parsing of target string arguments. Result: Fail fast with invalid request Patch: https://rb.dcache.org/r/14312/ Acked-by: Tigran Target: trunk Request: 10.x, 9.x --- .../restful/resources/bulk/BulkResources.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/bulk/BulkResources.java b/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/bulk/BulkResources.java index ecdad401731..6a0bf16da2d 100644 --- a/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/bulk/BulkResources.java +++ b/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/bulk/BulkResources.java @@ -595,14 +595,24 @@ private static List extractTarget(Map map) { int close = stringTarget.indexOf("]"); stringTarget = stringTarget.substring(open+1, close); } - return Arrays.stream(stringTarget.split("[,]")).collect(Collectors.toList()); + return Arrays.stream(stringTarget.split("[,]")) + .filter(i-> !i.isEmpty()) + .collect(Collectors.toList()); } else if (target instanceof String[]) { - return Arrays.stream(((String) target).split("[,]")).collect(Collectors.toList()); + return Arrays.stream(((String) target).split("[,]")) + .map(String::strip) + .filter(i-> !i.isEmpty()) + .collect(Collectors.toList()); } else { - return (List) target; + return ((List) target) + .stream() + .map(String::strip) + .filter(i -> !i.isEmpty()) + .collect(Collectors.toList()); } } + private static T removeEntry(Map map, Class clzz, String... names) { T value = null; for (String name : names) {