mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 379034 - Relative URLs with capitalized schemes are treated as absolute, r=biesi sr=bzbarsky
This commit is contained in:
parent
59f047cd2e
commit
96ad2865a5
@ -622,7 +622,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStandardURL::SegmentIs(const URLSegment &seg, const char *val)
|
||||
nsStandardURL::SegmentIs(const URLSegment &seg, const char *val, PRBool ignoreCase)
|
||||
{
|
||||
// one or both may be null
|
||||
if (!val || mSpec.IsEmpty())
|
||||
@ -631,12 +631,16 @@ nsStandardURL::SegmentIs(const URLSegment &seg, const char *val)
|
||||
return PR_FALSE;
|
||||
// if the first |seg.mLen| chars of |val| match, then |val| must
|
||||
// also be null terminated at |seg.mLen|.
|
||||
return !strncmp(mSpec.get() + seg.mPos, val, seg.mLen)
|
||||
&& (val[seg.mLen] == '\0');
|
||||
if (ignoreCase)
|
||||
return !PL_strncasecmp(mSpec.get() + seg.mPos, val, seg.mLen)
|
||||
&& (val[seg.mLen] == '\0');
|
||||
else
|
||||
return !strncmp(mSpec.get() + seg.mPos, val, seg.mLen)
|
||||
&& (val[seg.mLen] == '\0');
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStandardURL::SegmentIs(const char* spec, const URLSegment &seg, const char *val)
|
||||
nsStandardURL::SegmentIs(const char* spec, const URLSegment &seg, const char *val, PRBool ignoreCase)
|
||||
{
|
||||
// one or both may be null
|
||||
if (!val || !spec)
|
||||
@ -645,18 +649,25 @@ nsStandardURL::SegmentIs(const char* spec, const URLSegment &seg, const char *va
|
||||
return PR_FALSE;
|
||||
// if the first |seg.mLen| chars of |val| match, then |val| must
|
||||
// also be null terminated at |seg.mLen|.
|
||||
return !strncmp(spec + seg.mPos, val, seg.mLen)
|
||||
&& (val[seg.mLen] == '\0');
|
||||
if (ignoreCase)
|
||||
return !PL_strncasecmp(spec + seg.mPos, val, seg.mLen)
|
||||
&& (val[seg.mLen] == '\0');
|
||||
else
|
||||
return !strncmp(spec + seg.mPos, val, seg.mLen)
|
||||
&& (val[seg.mLen] == '\0');
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsStandardURL::SegmentIs(const URLSegment &seg1, const char *val, const URLSegment &seg2)
|
||||
nsStandardURL::SegmentIs(const URLSegment &seg1, const char *val, const URLSegment &seg2, PRBool ignoreCase)
|
||||
{
|
||||
if (seg1.mLen != seg2.mLen)
|
||||
return PR_FALSE;
|
||||
if (seg1.mLen == -1 || (!val && mSpec.IsEmpty()))
|
||||
return PR_TRUE; // both are empty
|
||||
return !strncmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);
|
||||
if (ignoreCase)
|
||||
return !PL_strncasecmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);
|
||||
else
|
||||
return !strncmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
@ -1692,7 +1703,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
if (scheme.mLen >= 0) {
|
||||
// add some flags to coalesceFlag if it is an ftp-url
|
||||
// need this later on when coalescing the resulting URL
|
||||
if (SegmentIs(relpath, scheme, "ftp")) {
|
||||
if (SegmentIs(relpath, scheme, "ftp", PR_TRUE)) {
|
||||
coalesceFlag = (netCoalesceFlags) (coalesceFlag
|
||||
| NET_COALESCE_ALLOW_RELATIVE_ROOT
|
||||
| NET_COALESCE_DOUBLE_SLASH_IS_ROOT);
|
||||
@ -1700,7 +1711,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
}
|
||||
// this URL appears to be absolute
|
||||
// but try to find out more
|
||||
if (SegmentIs(mScheme,relpath,scheme)) {
|
||||
if (SegmentIs(mScheme, relpath, scheme, PR_TRUE)) {
|
||||
// mScheme and Scheme are the same
|
||||
// but this can still be relative
|
||||
if (nsCRT::strncmp(relpath + scheme.mPos + scheme.mLen,
|
||||
|
@ -167,9 +167,9 @@ private:
|
||||
|
||||
nsresult BuildNormalizedSpec(const char *spec);
|
||||
|
||||
PRBool SegmentIs(const URLSegment &s1, const char *val);
|
||||
PRBool SegmentIs(const char* spec, const URLSegment &s1, const char *val);
|
||||
PRBool SegmentIs(const URLSegment &s1, const char *val, const URLSegment &s2);
|
||||
PRBool SegmentIs(const URLSegment &s1, const char *val, PRBool ignoreCase = PR_FALSE);
|
||||
PRBool SegmentIs(const char* spec, const URLSegment &s1, const char *val, PRBool ignoreCase = PR_FALSE);
|
||||
PRBool SegmentIs(const URLSegment &s1, const char *val, const URLSegment &s2, PRBool ignoreCase = PR_FALSE);
|
||||
|
||||
PRInt32 ReplaceSegment(PRUint32 pos, PRUint32 len, const char *val, PRUint32 valLen);
|
||||
PRInt32 ReplaceSegment(PRUint32 pos, PRUint32 len, const nsACString &val);
|
||||
|
18
netwerk/test/unit/test_bug379034.js
Normal file
18
netwerk/test/unit/test_bug379034.js
Normal file
@ -0,0 +1,18 @@
|
||||
function run_test() {
|
||||
const ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
var base = ios.newURI("http://localhost/bug379034/index.html", null, null);
|
||||
|
||||
var uri = ios.newURI("http:a.html", null, base);
|
||||
do_check_eq(uri.spec, "http://localhost/bug379034/a.html");
|
||||
|
||||
uri = ios.newURI("HtTp:b.html", null, base);
|
||||
do_check_eq(uri.spec, "http://localhost/bug379034/b.html");
|
||||
|
||||
uri = ios.newURI("https:c.html", null, base);
|
||||
do_check_eq(uri.spec, "https://c.html/");
|
||||
|
||||
uri = ios.newURI("./https:d.html", null, base);
|
||||
do_check_eq(uri.spec, "http://localhost/bug379034/https:d.html");
|
||||
}
|
Loading…
Reference in New Issue
Block a user