Skip to content

Commit 2c32c77

Browse files
committed
Polishing in VersionRequestCondition
See gh-35237
1 parent 2238121 commit 2c32c77

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/VersionRequestCondition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ else if (this.version != null && otherVersion != null) {
128128
return (-1 * compareVersions(this.version, otherVersion));
129129
}
130130
else {
131-
// Prefer mapping without version for unversioned request
131+
// Prefer mappings with a version unless the request is without a version
132+
int result = this.version != null ? -1 : 1;
132133
Comparable<?> version = exchange.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE);
133-
return (version != null ? (this.version != null ? -1 : 1) : (this.version != null ? 1 : -1));
134+
return (version == null ? -1 * result : result);
134135
}
135136
}
136137

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/VersionRequestCondition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ else if (this.version != null && otherVersion != null) {
127127
return (-1 * compareVersions(this.version, otherVersion));
128128
}
129129
else {
130-
// Prefer mapping without version for unversioned request
130+
// Prefer mappings with a version unless the request is without a version
131+
int result = this.version != null ? -1 : 1;
131132
Comparable<?> version = (Comparable<?>) request.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE);
132-
return (version != null ? (this.version != null ? -1 : 1) : (this.version != null ? 1 : -1));
133+
return (version == null ? -1 * result : result);
133134
}
134135
}
135136

0 commit comments

Comments
 (0)