From e92bbc801418901e2e5f394b6764860cb37f45d2 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 26 Mar 2014 11:37:11 -0400 Subject: [PATCH] Revert "Improve suffix pattern check" This reverts commit 3474afb165b6efa1a15db87c088e0fe79353000f. Unfortunately this change is likely to cause issues for applications that use regular expressions in a URI variable. I think we will have to leave at: if there are any dots in the last segment of the request path, regardless of whether they're in a URI var or not, the suffix pattern match is off. Issue: SPR-11532 --- .../condition/PatternsRequestCondition.java | 25 ++----------------- .../PatternsRequestConditionTests.java | 22 +--------------- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java index 50ab3fca614..4ccd60391ec 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java @@ -249,7 +249,8 @@ public final class PatternsRequestCondition extends AbstractRequestCondition 0; i--) { - char c = pattern.charAt(i-1); - if (c == '}') { - uriVarMode = true; - } - else if (c == '{') { - uriVarMode = false; - } - else if (c == '/') { - return false; - } - else { - if (!uriVarMode && c == '.') { - return true; - } - } - } - return false; - } - /** * Compare the two conditions based on the URL patterns they contain. * Patterns are compared one at a time, from top to bottom via diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java index 6e58a1a743b..749d6314aaf 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,26 +115,6 @@ public class PatternsRequestConditionTests { assertEquals("/{foo}", match.getPatterns().iterator().next()); } - // SPR-11532 - - @Test - public void matchSuffixPatternWithUriVariables() { - testSuffixPattern("/employees/{areaOfResponsibility.owner.id}", "/employees/976685.json", false); - testSuffixPattern("/establishments/{establishmentId}", "/establishments/123456789.json", false); - testSuffixPattern("/a.b/c", "/a.b/c.json", false); - testSuffixPattern("/a/b.json", "/a/b.json", true); - testSuffixPattern("/a/{b}.{c}", "/a/b.c", true); - } - - public void testSuffixPattern(String pattern, String url, boolean patternHasSuffix) { - MockHttpServletRequest request = new MockHttpServletRequest("GET", url); - PatternsRequestCondition condition = new PatternsRequestCondition(pattern); - PatternsRequestCondition match = condition.getMatchingCondition(request); - - assertNotNull(match); - assertEquals((patternHasSuffix ? pattern : pattern + ".*"), match.getPatterns().iterator().next()); - } - // SPR-8410 @Test