471464 - Parsing issues with HttpURI

Removed pre-existing lookahead
made {} style more consistent
This commit is contained in:
Greg Wilkins 2015-07-01 13:36:49 +10:00
parent 97e5b86b26
commit dd9e3d8ee9
1 changed files with 17 additions and 50 deletions

View File

@ -124,7 +124,7 @@ public class HttpURI
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public HttpURI(String uri) public HttpURI(String uri)
{ {
parse(uri); _port=-1;
parse(State.START,uri,0,uri.length()); parse(State.START,uri,0,uri.length());
} }
@ -226,7 +226,13 @@ public class HttpURI
default: default:
mark=i; mark=i;
state=State.SCHEME_OR_PATH; if (_scheme==null)
state=State.SCHEME_OR_PATH;
else
{
path_mark=i;
state=State.PATH;
}
} }
continue; continue;
@ -237,54 +243,41 @@ public class HttpURI
switch (c) switch (c)
{ {
case ':': case ':':
{
// must have been a scheme // must have been a scheme
_scheme=uri.substring(mark,i); _scheme=uri.substring(mark,i);
c = uri.charAt(++i); // Start again with scheme set
mark=i; state=State.START;
if (c == '/')
state=State.HOST_OR_PATH;
else
state=State.PATH;
break; break;
}
case '/': case '/':
{
// must have been in a path and still are // must have been in a path and still are
state=State.PATH; state=State.PATH;
break; break;
}
case ';': case ';':
{
// must have been in a path // must have been in a path
mark=i+1; mark=i+1;
state=State.PARAM; state=State.PARAM;
break; break;
}
case '?': case '?':
{
// must have been in a path // must have been in a path
_path=uri.substring(mark,i); _path=uri.substring(mark,i);
mark=i+1; mark=i+1;
state=State.QUERY; state=State.QUERY;
break; break;
}
case '%': case '%':
{ // must have be in an encoded path
encoded=true; encoded=true;
} state=State.PATH;
break;
case '#': case '#':
{
// must have been in a path // must have been in a path
_path=uri.substring(mark,i); _path=uri.substring(mark,i);
state=State.FRAGMENT; state=State.FRAGMENT;
break; break;
}
} }
continue; continue;
} }
@ -325,31 +318,24 @@ public class HttpURI
switch (c) switch (c)
{ {
case '/': case '/':
{ _host = uri.substring(mark,i);
if (i > mark)
_host = uri.substring(mark,i);
path_mark=mark=i; path_mark=mark=i;
state=State.PATH; state=State.PATH;
break; break;
}
case ':': case ':':
{
if (i > mark) if (i > mark)
_host=uri.substring(mark,i); _host=uri.substring(mark,i);
mark=i+1; mark=i+1;
state=State.PORT; state=State.PORT;
break; break;
}
case '@': case '@':
_user=uri.substring(mark,i); _user=uri.substring(mark,i);
mark=i+1; mark=i+1;
break; break;
case '[': case '[':
{
state=State.IPV6; state=State.IPV6;
break; break;
}
} }
continue; continue;
} }
@ -359,11 +345,8 @@ public class HttpURI
switch (c) switch (c)
{ {
case '/': case '/':
{
throw new IllegalArgumentException("No closing ']' for ipv6 in " + uri); throw new IllegalArgumentException("No closing ']' for ipv6 in " + uri);
}
case ']': case ']':
{
c = uri.charAt(++i); c = uri.charAt(++i);
_host=uri.substring(mark,i); _host=uri.substring(mark,i);
if (c == ':') if (c == ':')
@ -377,7 +360,6 @@ public class HttpURI
state=State.PATH; state=State.PATH;
} }
break; break;
}
} }
continue; continue;
@ -399,29 +381,22 @@ public class HttpURI
switch (c) switch (c)
{ {
case ';': case ';':
{
mark=i+1; mark=i+1;
state=State.PARAM; state=State.PARAM;
break; break;
}
case '?': case '?':
{
_path=uri.substring(path_mark,i); _path=uri.substring(path_mark,i);
mark=i+1; mark=i+1;
state=State.QUERY; state=State.QUERY;
break; break;
}
case '#': case '#':
{
_path=uri.substring(path_mark,i); _path=uri.substring(path_mark,i);
mark=i+1; mark=i+1;
state=State.FRAGMENT; state=State.FRAGMENT;
break; break;
}
case '%': case '%':
{
encoded=true; encoded=true;
} break;
} }
continue; continue;
} }
@ -431,34 +406,26 @@ public class HttpURI
switch (c) switch (c)
{ {
case '?': case '?':
{
_path=uri.substring(path_mark,i); _path=uri.substring(path_mark,i);
_param=uri.substring(mark,i); _param=uri.substring(mark,i);
mark=i+1; mark=i+1;
state=State.QUERY; state=State.QUERY;
break; break;
}
case '#': case '#':
{
_path=uri.substring(path_mark,i); _path=uri.substring(path_mark,i);
_param=uri.substring(mark,i); _param=uri.substring(mark,i);
mark=i+1; mark=i+1;
state=State.FRAGMENT; state=State.FRAGMENT;
break; break;
}
case '/': case '/':
{
encoded=true; encoded=true;
// ignore internal params // ignore internal params
state=State.PATH; state=State.PATH;
break; break;
}
case ';': case ';':
{
// multiple parameters // multiple parameters
mark=i+1; mark=i+1;
break; break;
}
} }
continue; continue;
} }
@ -636,7 +603,7 @@ public class HttpURI
public void clear() public void clear()
{ {
_uri=null; _uri=null;
_scheme=null; _scheme=null;
_host=null; _host=null;
_port=-1; _port=-1;
@ -644,7 +611,7 @@ public class HttpURI
_param=null; _param=null;
_query=null; _query=null;
_fragment=null; _fragment=null;
_decodedPath=null; _decodedPath=null;
} }