@@ -156,15 +156,15 @@ public String getPatternString() {
156156 return this .patternString ;
157157 }
158158
159-
160159 /**
161160 * Whether this pattern matches the given path.
162161 * @param pathContainer the candidate path to attempt to match against
163162 * @return {@code true} if the path matches this pattern
164163 */
165164 public boolean matches (PathContainer pathContainer ) {
166165 if (this .head == null ) {
167- return !hasLength (pathContainer );
166+ return !hasLength (pathContainer ) ||
167+ (this .matchOptionalTrailingSeparator && pathContainerIsJustSeparator (pathContainer ));
168168 }
169169 else if (!hasLength (pathContainer )) {
170170 if (this .head instanceof WildcardTheRestPathElement || this .head instanceof CaptureTheRestPathElement ) {
@@ -187,7 +187,9 @@ else if (!hasLength(pathContainer)) {
187187 @ Nullable
188188 public PathMatchInfo matchAndExtract (PathContainer pathContainer ) {
189189 if (this .head == null ) {
190- return hasLength (pathContainer ) ? null : PathMatchInfo .EMPTY ;
190+ return hasLength (pathContainer ) &&
191+ !(this .matchOptionalTrailingSeparator && pathContainerIsJustSeparator (pathContainer ))
192+ ? null : PathMatchInfo .EMPTY ;
191193 }
192194 else if (!hasLength (pathContainer )) {
193195 if (this .head instanceof WildcardTheRestPathElement || this .head instanceof CaptureTheRestPathElement ) {
@@ -708,5 +710,10 @@ private boolean hasLength(@Nullable PathContainer container) {
708710 private static int scoreByNormalizedLength (PathPattern pattern ) {
709711 return -pattern .getNormalizedLength ();
710712 }
713+
714+ private boolean pathContainerIsJustSeparator (PathContainer pathContainer ) {
715+ return pathContainer .value ().length () == 1 &&
716+ pathContainer .value ().charAt (0 ) == separator ;
717+ }
711718
712719}
0 commit comments