Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 4332c1b

Browse files
author
Dave Syer
committed
Added test cases for SPR-8683
1 parent 7b8501f commit 4332c1b

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

SPR-8683/pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-8683</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<dependencies>
9+
<dependency>
10+
<groupId>org.springframework</groupId>
11+
<artifactId>spring-context</artifactId>
12+
<version>3.1.0.BUILD-SNAPSHOT</version>
13+
</dependency>
14+
<dependency>
15+
<groupId>log4j</groupId>
16+
<artifactId>log4j</artifactId>
17+
<version>1.2.16</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.8</version>
23+
<scope>test</scope>
24+
</dependency>
25+
</dependencies>
26+
<repositories>
27+
<repository>
28+
<id>spring-maven-snapshot</id>
29+
<name>Springframework Maven Snapshot Repository</name>
30+
<url>http://maven.springframework.org/snapshot</url>
31+
<snapshots><enabled>true</enabled></snapshots>
32+
</repository>
33+
</repositories>
34+
<properties>
35+
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
36+
</properties>
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>2.3.2</version>
42+
<configuration>
43+
<source>1.6</source>
44+
<target>1.6</target>
45+
</configuration>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-surefire-plugin</artifactId>
49+
<version>2.7.2</version>
50+
<configuration>
51+
<includes>
52+
<include>**/*Tests.java</include>
53+
</includes>
54+
<excludes>
55+
<exclude>**/*Abstract*.java</exclude>
56+
</excludes>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
</project>
62+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.springframework.issues;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.util.Comparator;
6+
7+
import org.junit.Test;
8+
import org.springframework.util.AntPathMatcher;
9+
10+
// Negative means we prefer the first argument when both patterns match
11+
public class ReproTests {
12+
13+
@Test
14+
public void patternComparatorWithHierarchicalMatchAccidentalPass() {
15+
Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new");
16+
// This passes accidentally: the order is correct but for the wrong reason
17+
assertTrue(comparator.compare("/hotels/{hotel}", "/hotels/**") < 0);
18+
}
19+
20+
@Test
21+
public void patternComparatorWithHierarchicalMatchBracketsPreferred() {
22+
Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new/123");
23+
// This passes accidentally: the order is correct but for the wrong reason
24+
assertTrue(comparator.compare("/hotels/{hotel}/{booking}", "/hotels/**") < 0);
25+
}
26+
27+
@Test
28+
public void patternComparatorWithHierarchicalMatch() {
29+
Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new/123");
30+
// This fails, even though the first path is clearly more specific
31+
assertTrue(comparator.compare("/hotels/{hotel}/**", "/**") < 0);
32+
}
33+
34+
@Test
35+
public void patternComparatorWithHierarchicalMatchWithWorkaround() {
36+
Comparator<String> comparator = new AntPathMatcher().getPatternComparator("/hotels/new/123");
37+
// This is a workaround
38+
assertTrue(comparator.compare("/hotels/{hotel}/**", "/**/**") < 0);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)