joerghoh commented on code in PR #88:
URL:
https://github.com/apache/sling-org-apache-sling-api/pull/88#discussion_r4538725416
##########
src/main/java/org/apache/sling/api/request/header/MediaRangeList.java:
##########
@@ -199,18 +221,24 @@ public MediaRange(String exp) {
String[] parts = exp.split(";");
this.setType(parts[0].trim());
if (parts.length > 1) {
- this.parameters = new HashMap<String, String>(parts.length -
1);
+ this.parameters = new LinkedHashMap<String,
String>(parts.length - 1);
}
for (int i = 1, partsLength = parts.length; i < partsLength; i++) {
- String parameter = parts[i];
- String[] keyValue = parameter.split("=");
- if (keyValue[0].equals("q")) {
- this.q = Double.parseDouble(keyValue[1]);
- if (this.q < 0 || this.q > 1) {
+ String[] keyValue = parts[i].split("=", 2);
+ if (keyValue.length != 2
+ || keyValue[0].trim().isEmpty()
+ || keyValue[1].trim().isEmpty()) {
+ throw new IllegalArgumentException("Invalid media range
parameter: " + exp);
+ }
+ String name = keyValue[0].trim().toLowerCase(Locale.ROOT);
+ String value = keyValue[1].trim();
+ if (name.equals("q")) {
+ this.q = Double.parseDouble(value);
+ if (!Double.isFinite(this.q) || this.q < 0 || this.q > 1) {
throw new IllegalArgumentException("Quality factor out
of bounds: " + exp);
}
}
- this.parameters.put(keyValue[0], keyValue[1]);
+ this.parameters.put(name, value);
Review Comment:
implemented that feedback
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]