Skip to content

Commit

Permalink
improve the code of URLStrParser.java (apache#8085)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongxiongzeng authored Jun 21, 2021
1 parent 3caddb0 commit c8cefee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static URL valueOf(String url) {
Map<String, String> parameters = null;
int i = url.indexOf('?'); // separator between body and parameters
if (i >= 0) {
String[] parts = url.substring(i + 1).split("&");
String[] parts = url.substring(i + 1).split("[&;]");
parameters = new HashMap<>();
for (String part : parts) {
part = part.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,32 +224,20 @@ private static boolean addParam(String str, boolean isEncoded, int nameStart, in
valueStart = valueEnd + 1;
}

String name;
String value;
if (isEncoded) {
String name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf);
String value = decodeComponent(str, valueStart, valueEnd, false, tempBuf);
if (valueStart == valueEnd) {
value = name;
} else {
value = decodeComponent(str, valueStart, valueEnd, false, tempBuf);
}
params.put(name, value);
// compatible with lower versions registering "default." keys
if (name.startsWith(DEFAULT_KEY_PREFIX)) {
params.putIfAbsent(name.substring(DEFAULT_KEY_PREFIX.length()), value);
}
name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf);
value = valueStart == valueEnd ? name : decodeComponent(str, valueStart, valueEnd, false, tempBuf);
} else {
String name = str.substring(nameStart, valueStart - 1);
String value = str.substring(valueStart, valueEnd);
if (valueStart == valueEnd) {
value = name;
} else {
value = str.substring(valueStart, valueEnd);
}
params.put(name, value);
// compatible with lower versions registering "default." keys
if (name.startsWith(DEFAULT_KEY_PREFIX)) {
params.putIfAbsent(name.substring(DEFAULT_KEY_PREFIX.length()), value);
}
name = str.substring(nameStart, valueStart - 1);
value = valueStart == valueEnd ? name : str.substring(valueStart, valueEnd);
}

params.put(name, value);
// compatible with lower versions registering "default." keys
if (name.startsWith(DEFAULT_KEY_PREFIX)) {
params.putIfAbsent(name.substring(DEFAULT_KEY_PREFIX.length()), value);
}
return true;
}
Expand Down

0 comments on commit c8cefee

Please sign in to comment.