From 88b73de3b74d6dfd7cdd3d7d3c010a16356053ee Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 8 Aug 2018 08:44:43 +0200 Subject: [PATCH] DATAREST-1274 - JsonPatch paths now properly verify multi-digit indexes. --- .../data/rest/webmvc/json/patch/SpelPath.java | 2 +- .../rest/webmvc/json/patch/SpelPathUnitTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java index b1e40e5d2..24eb7f56d 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java @@ -450,7 +450,7 @@ class SpelPath { Assert.notNull(type, "Type must not be null!"); String pathSource = Arrays.stream(path.split("/"))// - .filter(it -> !it.matches("\\d")) // no digits + .filter(it -> !it.matches("\\d+")) // no digits .filter(it -> !it.equals("-")) // no "last element"s .filter(it -> !it.isEmpty()) // .collect(Collectors.joining(".")); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java index b5dc03a02..697ff58c5 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/SpelPathUnitTests.java @@ -15,6 +15,7 @@ */ package org.springframework.data.rest.webmvc.json.patch; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.*; import java.util.ArrayList; @@ -23,6 +24,11 @@ import java.util.List; import org.junit.Test; import org.springframework.data.rest.webmvc.json.patch.SpelPath.TypedSpelPath; +/** + * Unit tests for {@link SpelPath}. + * + * @author Oliver Gierke + */ public class SpelPathUnitTests { @Test @@ -69,4 +75,9 @@ public class SpelPathUnitTests { assertSame(left, right); } + + @Test // DATAREST-1274 + public void supportsMultiDigitCollectionIndex() { + assertThat(SpelPath.of("/11/description").getLeafType(Todo.class)).isEqualTo(String.class); + } }