From c0d467fed49b8bf13bcd3e4f42bdadba93823113 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Mon, 27 Jan 2025 11:40:23 +0100 Subject: [PATCH] refactor: Use `SchemaNames` to escape and sanitze labels used in SpEL. Signed-off-by: Michael Simons --- .../data/neo4j/repository/query/Neo4jSpelSupport.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java b/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java index 7eb0e991f..a85a6a781 100644 --- a/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java +++ b/src/main/java/org/springframework/data/neo4j/repository/query/Neo4jSpelSupport.java @@ -18,10 +18,8 @@ package org.springframework.data.neo4j.repository.query; import java.io.Serial; import java.util.Collection; import java.util.LinkedHashMap; -import java.util.Locale; import java.util.Map; import java.util.concurrent.locks.StampedLock; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -248,10 +246,7 @@ public final class Neo4jSpelSupport { .getRequiredPersistentEntity(metadata.getJavaType()); evalContext.setVariable(ENTITY_NAME, requiredPersistentEntity.getStaticLabels() .stream() - .map(l -> { - Matcher matcher = LABEL_AND_TYPE_QUOTATION.matcher(l); - return String.format(Locale.ENGLISH, "`%s`", matcher.replaceAll("``")); - }) + .map(l -> SchemaNames.sanitize(l, true).orElseThrow()) .collect(Collectors.joining(":"))); query = potentiallyQuoteExpressionsParameter(query);