Skip to content

Commit 7b69726

Browse files
committed
PathPatternParser allows '-' in variables
The isJavaIdentifier check is not really required, but also seems intuitive for variables to be Java identifier-like. This commit relaxes the constraint a bit by also allowing "-". Closes gh-23101
1 parent 1d92755 commit 7b69726

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

spring-web/src/main/java/org/springframework/web/util/pattern/InternalPathPatternParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -172,7 +172,7 @@ else if (ch == '*') {
172172

173173
}
174174
else if ((this.pos > (this.variableCaptureStart + 1 + (this.isCaptureTheRestVariable ? 1 : 0)) &&
175-
!Character.isJavaIdentifierPart(ch))) {
175+
!Character.isJavaIdentifierPart(ch) && ch != '-')) {
176176
throw new PatternParseException(this.pos, this.pathPatternData,
177177
PatternMessage.ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR,
178178
Character.toString(ch));

spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternParserTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -185,6 +185,7 @@ public void completeCapturingPatterns() {
185185
checkStructure("/{foo}");
186186
checkStructure("/{f}/");
187187
checkStructure("/{foo}/{bar}/{wibble}");
188+
checkStructure("/{mobile-number}"); // gh-23101
188189
}
189190

190191
@Test

0 commit comments

Comments
 (0)