]>
Commit | Line | Data |
---|---|---|
687c1682 ER |
1 | Index: nsStandardURL.cpp |
2 | =================================================================== | |
3 | RCS file: /cvs/mozilla/netwerk/base/src/nsStandardURL.cpp,v | |
4 | retrieving revision 1.60.16.2 | |
5 | diff -p -u -1 -2 -r1.60.16.2 nsStandardURL.cpp | |
6 | --- 1/netwerk/base/src/nsStandardURL.cpp 17 Feb 2005 23:40:53 -0000 1.60.16.2 | |
7 | +++ 2/netwerk/base/src/nsStandardURL.cpp 9 Sep 2005 16:34:46 -0000 | |
8 | @@ -403,24 +403,25 @@ nsStandardURL::AppendToBuf(char *buf, PR | |
9 | // 4- update url segment positions and lengths | |
10 | nsresult | |
11 | nsStandardURL::BuildNormalizedSpec(const char *spec) | |
12 | { | |
13 | // Assumptions: all member URLSegments must be relative the |spec| argument | |
14 | // passed to this function. | |
15 | ||
16 | // buffers for holding escaped url segments (these will remain empty unless | |
17 | // escaping is required). | |
18 | nsCAutoString encUsername; | |
19 | nsCAutoString encPassword; | |
20 | nsCAutoString encHost; | |
21 | + PRBool useEncHost; | |
22 | nsCAutoString encDirectory; | |
23 | nsCAutoString encBasename; | |
24 | nsCAutoString encExtension; | |
25 | nsCAutoString encParam; | |
26 | nsCAutoString encQuery; | |
27 | nsCAutoString encRef; | |
28 | ||
29 | // | |
30 | // escape each URL segment, if necessary, and calculate approximate normalized | |
31 | // spec length. | |
32 | // | |
33 | PRInt32 approxLen = 3; // includes room for "://" | |
34 | @@ -440,34 +441,36 @@ nsStandardURL::BuildNormalizedSpec(const | |
35 | approxLen += encoder.EncodeSegmentCount(spec, mBasename, esc_FileBaseName, encBasename); | |
36 | approxLen += encoder.EncodeSegmentCount(spec, mExtension, esc_FileExtension, encExtension); | |
37 | approxLen += encoder.EncodeSegmentCount(spec, mParam, esc_Param, encParam); | |
38 | approxLen += encoder.EncodeSegmentCount(spec, mQuery, esc_Query, encQuery); | |
39 | approxLen += encoder.EncodeSegmentCount(spec, mRef, esc_Ref, encRef); | |
40 | } | |
41 | ||
42 | // do not escape the hostname, if IPv6 address literal, mHost will | |
43 | // already point to a [ ] delimited IPv6 address literal. | |
44 | // However, perform Unicode normalization on it, as IDN does. | |
45 | mHostEncoding = eEncoding_ASCII; | |
46 | if (mHost.mLen > 0) { | |
47 | + useEncHost = PR_FALSE; | |
48 | const nsCSubstring& tempHost = | |
49 | Substring(spec + mHost.mPos, spec + mHost.mPos + mHost.mLen); | |
50 | if (IsASCII(tempHost)) | |
51 | approxLen += mHost.mLen; | |
52 | else { | |
53 | mHostEncoding = eEncoding_UTF8; | |
54 | if (gIDNService && | |
55 | - NS_SUCCEEDED(gIDNService->Normalize(tempHost, encHost))) | |
56 | + NS_SUCCEEDED(gIDNService->Normalize(tempHost, encHost))) { | |
57 | approxLen += encHost.Length(); | |
58 | - else { | |
59 | + useEncHost = PR_TRUE; | |
60 | + } else { | |
61 | encHost.Truncate(); | |
62 | approxLen += mHost.mLen; | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | // | |
68 | // generate the normalized URL string | |
69 | // | |
70 | mSpec.SetLength(approxLen + 32); | |
71 | char *buf; | |
72 | mSpec.BeginWriting(buf); | |
73 | @@ -483,25 +486,30 @@ nsStandardURL::BuildNormalizedSpec(const | |
74 | mAuthority.mPos = i; | |
75 | ||
76 | // append authority | |
77 | if (mUsername.mLen > 0) { | |
78 | i = AppendSegmentToBuf(buf, i, spec, mUsername, &encUsername); | |
79 | if (mPassword.mLen >= 0) { | |
80 | buf[i++] = ':'; | |
81 | i = AppendSegmentToBuf(buf, i, spec, mPassword, &encPassword); | |
82 | } | |
83 | buf[i++] = '@'; | |
84 | } | |
85 | if (mHost.mLen > 0) { | |
86 | - i = AppendSegmentToBuf(buf, i, spec, mHost, &encHost); | |
87 | + if (useEncHost) { | |
88 | + mHost.mPos = i; | |
89 | + mHost.mLen = encHost.Length(); | |
90 | + i = AppendToBuf(buf, i, encHost.get(), mHost.mLen); | |
91 | + } else | |
92 | + i = AppendSegmentToBuf(buf, i, spec, mHost); | |
93 | net_ToLowerCase(buf + mHost.mPos, mHost.mLen); | |
94 | if (mPort != -1 && mPort != mDefaultPort) { | |
95 | nsCAutoString portbuf; | |
96 | portbuf.AppendInt(mPort); | |
97 | buf[i++] = ':'; | |
98 | i = AppendToBuf(buf, i, portbuf.get(), portbuf.Length()); | |
99 | } | |
100 | } | |
101 | ||
102 | // record authority length | |
103 | mAuthority.mLen = i - mAuthority.mPos; | |
104 |