fix bug that lowercases userInfo part

This commit is contained in:
Jörg Prante 2019-01-17 18:33:19 +01:00
parent 3c00b77d98
commit b23fe28c42
2 changed files with 11 additions and 5 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = net name = net
version = 1.2.0 version = 1.2.1
jackson.version = 2.8.11 jackson.version = 2.8.11
junit.version = 4.12 junit.version = 4.12

View file

@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -785,13 +786,17 @@ public class URL implements Comparable<URL> {
} }
public Builder host(String host) { public Builder host(String host) {
this.host = host; if (host != null) {
this.host = host.toLowerCase(Locale.ROOT);
}
this.protocolVersion = ProtocolVersion.NONE; this.protocolVersion = ProtocolVersion.NONE;
return this; return this;
} }
public Builder host(String host, ProtocolVersion protocolVersion) { public Builder host(String host, ProtocolVersion protocolVersion) {
this.host = host; if (host != null) {
this.host = host.toLowerCase(Locale.ROOT);
}
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
return this; return this;
} }
@ -1003,7 +1008,7 @@ public class URL implements Comparable<URL> {
int i = remaining.indexOf(SEPARATOR_CHAR); int i = remaining.indexOf(SEPARATOR_CHAR);
int j = remaining.indexOf(QUESTION_CHAR); int j = remaining.indexOf(QUESTION_CHAR);
int pos = i >= 0 && j >= 0 ? Math.min(i, j) : i >= 0 ? i : j >= 0 ? j : -1; int pos = i >= 0 && j >= 0 ? Math.min(i, j) : i >= 0 ? i : j >= 0 ? j : -1;
String host = (pos >= 0 ? remaining.substring(0, pos) : remaining).toLowerCase(); String host = (pos >= 0 ? remaining.substring(0, pos) : remaining);
parseHostAndPort(builder, parseUserInfo(builder, host), resolve); parseHostAndPort(builder, parseUserInfo(builder, host), resolve);
if (builder.host == null) { if (builder.host == null) {
return INVALID; return INVALID;
@ -1045,8 +1050,9 @@ public class URL implements Comparable<URL> {
return remaining; return remaining;
} }
private void parseHostAndPort(Builder builder, String host, boolean resolve) private void parseHostAndPort(Builder builder, String rawHost, boolean resolve)
throws URLSyntaxException { throws URLSyntaxException {
String host = rawHost;
if (host.indexOf('[') == 0) { if (host.indexOf('[') == 0) {
int i = host.lastIndexOf(']'); int i = host.lastIndexOf(']');
if (i >= 0) { if (i >= 0) {