Uri Parse improvements
This commit is contained in:
parent
a21cf9f7b8
commit
8d16abd980
@ -295,13 +295,7 @@ private:
|
||||
// Look for auth (//([^/?#]*))?
|
||||
auth_ = scheme_ + GetSchemeStringLength() + 1;
|
||||
*auth_ = '\0';
|
||||
if (start < len) {
|
||||
pos1 = start;
|
||||
while (pos1 < len) {
|
||||
if (uri[pos1] == '/' && uri[pos1 + 1] == '/') break;
|
||||
pos1++;
|
||||
}
|
||||
if (pos1 == start) {
|
||||
if (start < len - 1 && uri[start] == '/' && uri[start + 1] == '/') {
|
||||
pos2 = start + 2;
|
||||
while (pos2 < len) {
|
||||
if (uri[pos2] == '/') break;
|
||||
@ -313,7 +307,6 @@ private:
|
||||
auth_[pos2 - start] = '\0';
|
||||
start = pos2;
|
||||
}
|
||||
}
|
||||
// Look for path ([^?#]*)
|
||||
path_ = auth_ + GetAuthStringLength() + 1;
|
||||
*path_ = '\0';
|
||||
@ -335,8 +328,8 @@ private:
|
||||
// Look for query (\?([^#]*))?
|
||||
query_ = path_ + GetPathStringLength() + 1;
|
||||
*query_ = '\0';
|
||||
if (start < len) {
|
||||
pos2 = start;
|
||||
if (start < len && uri[start] == '?') {
|
||||
pos2 = start + 1;
|
||||
while (pos2 < len) {
|
||||
if (uri[pos2] == '#') break;
|
||||
pos2++;
|
||||
@ -350,7 +343,7 @@ private:
|
||||
// Look for fragment (#(.*))?
|
||||
frag_ = query_ + GetQueryStringLength() + 1;
|
||||
*frag_ = '\0';
|
||||
if (start < len) {
|
||||
if (start < len && uri[start] == '#') {
|
||||
std::memcpy(frag_, &uri[start], (len - start) * sizeof(Ch));
|
||||
frag_[len - start] = '\0';
|
||||
}
|
||||
|
@ -160,6 +160,14 @@ TEST(Uri, Parse) {
|
||||
EXPECT_TRUE(u.GetBaseStringLength() == 0);
|
||||
EXPECT_TRUE(StrCmp(u.GetFragString(), "#frag/stuff") == 0);
|
||||
EXPECT_TRUE(u.GetFragStringLength() == len);
|
||||
|
||||
// Incomplete auth treated as path
|
||||
str = "http:/";
|
||||
const UriType u2 = UriType(str);
|
||||
EXPECT_TRUE(StrCmp(u2.GetSchemeString(), "http:") == 0);
|
||||
EXPECT_TRUE(u2.GetAuthStringLength() == 0);
|
||||
EXPECT_TRUE(StrCmp(u2.GetPathString(), "/") == 0);
|
||||
EXPECT_TRUE(StrCmp(u2.GetBaseString(), "http:/") == 0);
|
||||
}
|
||||
|
||||
TEST(Uri, Parse_UTF16) {
|
||||
@ -274,6 +282,13 @@ TEST(Uri, Parse_UTF16) {
|
||||
EXPECT_TRUE(u.GetBaseStringLength() == 0);
|
||||
EXPECT_TRUE(StrCmp(u.GetFragString(), L"#frag/stuff") == 0);
|
||||
EXPECT_TRUE(u.GetFragStringLength() == len);
|
||||
|
||||
// Incomplete auth treated as path
|
||||
u = UriType(L"http:/");
|
||||
EXPECT_TRUE(StrCmp(u.GetSchemeString(), L"http:") == 0);
|
||||
EXPECT_TRUE(u.GetAuthStringLength() == 0);
|
||||
EXPECT_TRUE(StrCmp(u.GetPathString(), L"/") == 0);
|
||||
EXPECT_TRUE(StrCmp(u.GetBaseString(), L"http:/") == 0);
|
||||
}
|
||||
|
||||
TEST(Uri, CopyConstructor) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user