зеркало из https://github.com/mozilla/pjs.git
More URL parsing updates for not so common cases.
This commit is contained in:
Родитель
8bd7e118e9
Коммит
089b1a8da9
|
@ -249,8 +249,8 @@ switch (*nextbrk)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
break;
|
break;
|
||||||
case ':': // http://user:pass@host:port...
|
case ':': // http://user:pass@host:port...
|
||||||
lastbrk = brk;
|
lastbrk = brk+1;
|
||||||
brk = PL_strpbrk(lastbrk+1, "/?");
|
brk = PL_strpbrk(lastbrk, "/?");
|
||||||
if (brk) // http://user:pass@host:port/path
|
if (brk) // http://user:pass@host:port/path
|
||||||
{
|
{
|
||||||
mPort = ExtractPortFrom(mSpec, (lastbrk-mSpec),(brk-lastbrk));
|
mPort = ExtractPortFrom(mSpec, (lastbrk-mSpec),(brk-lastbrk));
|
||||||
|
@ -374,7 +374,7 @@ switch (*nextbrk)
|
||||||
|
|
||||||
ExtractString(mSpec, &mPreHost, 0, (brk-mSpec));
|
ExtractString(mSpec, &mPreHost, 0, (brk-mSpec));
|
||||||
lastbrk = brk+1;
|
lastbrk = brk+1;
|
||||||
brk = PL_strpbrk(lastbrk, ":/");
|
brk = PL_strpbrk(lastbrk, ":/?");
|
||||||
// its user:pass@host so everthing else is just the host
|
// its user:pass@host so everthing else is just the host
|
||||||
if (!brk)
|
if (!brk)
|
||||||
{
|
{
|
||||||
|
@ -403,7 +403,8 @@ switch (*nextbrk)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // (*brk == '/') so user:pass@host/path
|
else // (*brk == '/') || (*brk == '?')
|
||||||
|
// so user:pass@host/path
|
||||||
{
|
{
|
||||||
ExtractString(mSpec, &mPath, (brk - mSpec),
|
ExtractString(mSpec, &mPath, (brk - mSpec),
|
||||||
len - (brk - mSpec));
|
len - (brk - mSpec));
|
||||||
|
@ -437,7 +438,48 @@ switch (*nextbrk)
|
||||||
case '@' : // scheme:user@host...
|
case '@' : // scheme:user@host...
|
||||||
ExtractString(mSpec, &mPreHost, (lastbrk-mSpec),
|
ExtractString(mSpec, &mPreHost, (lastbrk-mSpec),
|
||||||
(brk-lastbrk));
|
(brk-lastbrk));
|
||||||
// TODO more here...
|
lastbrk = brk+1;
|
||||||
|
brk = PL_strpbrk(lastbrk, delimiters);
|
||||||
|
if (!brk) // scheme:user@host only
|
||||||
|
{
|
||||||
|
ExtractString(mSpec, &mHost, (lastbrk - mSpec),
|
||||||
|
len - (lastbrk-mSpec));
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
ExtractString(mSpec, &mHost, (lastbrk-mSpec),
|
||||||
|
(brk - lastbrk));
|
||||||
|
switch (*brk)
|
||||||
|
{
|
||||||
|
case ':' : // scheme:user@host:port...
|
||||||
|
lastbrk = brk+1;
|
||||||
|
brk = PL_strpbrk(lastbrk, "/?");
|
||||||
|
if (brk) // user:pass@host:port/path
|
||||||
|
{
|
||||||
|
mPort = ExtractPortFrom(mSpec,
|
||||||
|
(lastbrk-mSpec),(brk-lastbrk));
|
||||||
|
ExtractString(mSpec, &mPath,
|
||||||
|
(brk-mSpec), len - (brk-mSpec));
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
else // user:pass@host:port
|
||||||
|
{
|
||||||
|
mPort = ExtractPortFrom(mSpec,
|
||||||
|
(lastbrk-mSpec),len - (lastbrk-mSpec));
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '/' :
|
||||||
|
case '?' :
|
||||||
|
ExtractString(mSpec, &mPath,
|
||||||
|
(brk-mSpec), len - (brk-mSpec));
|
||||||
|
return NS_OK;
|
||||||
|
break;
|
||||||
|
case '@' : // bad case
|
||||||
|
return NS_ERROR_MALFORMED_URI;
|
||||||
|
break;
|
||||||
|
default: NS_POSTCONDITION(0, "This just can't be!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ':' : // scheme:user:pass@host...or scheme:host:port...
|
case ':' : // scheme:user:pass@host...or scheme:host:port...
|
||||||
/* TODO
|
/* TODO
|
||||||
|
|
|
@ -109,10 +109,10 @@ nsresult testURL(const char* i_pURL, PRBool bUseStd=PR_TRUE)
|
||||||
"http://username:password@hostname.com:80/pathname/./more/stuff/../path",
|
"http://username:password@hostname.com:80/pathname/./more/stuff/../path",
|
||||||
"username@host:8080/path",
|
"username@host:8080/path",
|
||||||
"http://gagan/",
|
"http://gagan/",
|
||||||
"host:port/netlib", //port should now be 0
|
"scheme:host/netlib",
|
||||||
"", //empty string
|
"", //empty string
|
||||||
"mailbox:///foo", // No host specified path should be /foo
|
"mailbox:///foo", // No host specified path should be /foo
|
||||||
"user:pass@hostname.edu:80/pathname", //this is always user:pass and not http:user
|
"scheme:user@hostname.edu:80/pathname", //this is always http:user and not user:pass
|
||||||
"http://username:password@hostname:80/pathname",
|
"http://username:password@hostname:80/pathname",
|
||||||
"resource:/pathname"
|
"resource:/pathname"
|
||||||
};
|
};
|
||||||
|
@ -122,10 +122,10 @@ nsresult testURL(const char* i_pURL, PRBool bUseStd=PR_TRUE)
|
||||||
"http,username:password,hostname.com,80,/pathname/more/path",
|
"http,username:password,hostname.com,80,/pathname/more/path",
|
||||||
",username,host,8080,/path",
|
",username,host,8080,/path",
|
||||||
"http,,gagan,-1,/",
|
"http,,gagan,-1,/",
|
||||||
",,host,0,/netlib",
|
"scheme,,host,-1,/netlib",
|
||||||
",,,-1,",
|
",,,-1,/",
|
||||||
"mailbox,,,-1,/foo",
|
"mailbox,,,-1,/foo",
|
||||||
",user:pass,hostname.edu,80,/pathname",
|
"scheme,user,hostname.edu,80,/pathname",
|
||||||
"http,username:password,hostname,80,/pathname",
|
"http,username:password,hostname,80,/pathname",
|
||||||
"resource,,,-1,/pathname"
|
"resource,,,-1,/pathname"
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче