|
|
|
Lines 109-142
nsDataHandler::NewURI(const nsACString &
|
Link Here
|
|---|
|
| 109 |
// Looks like a reference instead of a fully-specified URI. |
109 |
// Looks like a reference instead of a fully-specified URI. |
| 110 |
// --> initialize |uri| as a clone of |aBaseURI|, with ref appended. |
110 |
// --> initialize |uri| as a clone of |aBaseURI|, with ref appended. |
| 111 |
rv = aBaseURI->Clone(getter_AddRefs(uri)); |
111 |
rv = aBaseURI->Clone(getter_AddRefs(uri)); |
| 112 |
if (NS_FAILED(rv)) |
112 |
if (NS_FAILED(rv)) |
| 113 |
return rv; |
113 |
return rv; |
| 114 |
rv = uri->SetRef(spec); |
114 |
rv = uri->SetRef(spec); |
| 115 |
} else { |
115 |
} else { |
| 116 |
// Otherwise, we'll assume |spec| is a fully-specified data URI |
116 |
// Otherwise, we'll assume |spec| is a fully-specified data URI |
| 117 |
nsCAutoString contentType, contentCharset, dataBuffer; |
117 |
nsCAutoString contentType, contentCharset, dataBuffer, ref; |
| 118 |
PRBool base64; |
118 |
PRBool base64; |
| 119 |
rv = ParseURI(spec, contentType, contentCharset, base64, dataBuffer); |
119 |
rv = ParseURI(spec, contentType, contentCharset, base64, dataBuffer, ref); |
| 120 |
if (NS_FAILED(rv)) |
120 |
if (NS_FAILED(rv)) |
| 121 |
return rv; |
121 |
return rv; |
| 122 |
|
122 |
|
| 123 |
// Strip whitespace unless this is text, where whitespace is important |
123 |
// Strip whitespace unless this is text, where whitespace is important |
| 124 |
// Don't strip escaped whitespace though (bug 391951) |
124 |
// Don't strip escaped whitespace though (bug 391951) |
| 125 |
if (base64 || (strncmp(contentType.get(),"text/",5) != 0 && |
125 |
if (base64 || (strncmp(contentType.get(),"text/",5) != 0 && |
| 126 |
contentType.Find("xml") == kNotFound)) { |
126 |
contentType.Find("xml") == kNotFound)) { |
| 127 |
// it's ascii encoded binary, don't let any spaces in |
127 |
// it's ascii encoded binary, don't let any spaces in |
| 128 |
spec.StripWhitespace(); |
128 |
spec.StripWhitespace(); |
| 129 |
} |
129 |
} |
| 130 |
|
130 |
|
| 131 |
uri = do_CreateInstance(kSimpleURICID, &rv); |
131 |
uri = do_CreateInstance(kSimpleURICID, &rv); |
| 132 |
if (NS_FAILED(rv)) |
132 |
if (NS_FAILED(rv)) |
| 133 |
return rv; |
133 |
return rv; |
|
|
134 |
|
| 134 |
rv = uri->SetSpec(spec); |
135 |
rv = uri->SetSpec(spec); |
|
|
136 |
if (NS_FAILED(rv)) |
| 137 |
return rv; |
| 138 |
|
| 139 |
rv = uri->SetRef(ref); |
| 135 |
} |
140 |
} |
| 136 |
|
141 |
|
| 137 |
if (NS_FAILED(rv)) |
142 |
if (NS_FAILED(rv)) |
| 138 |
return rv; |
143 |
return rv; |
| 139 |
|
144 |
|
| 140 |
uri.forget(result); |
145 |
uri.forget(result); |
| 141 |
return rv; |
146 |
return rv; |
| 142 |
} |
147 |
} |
|
Lines 166-182
nsDataHandler::AllowPort(PRInt32 port, c
|
Link Here
|
|---|
|
| 166 |
return NS_OK; |
171 |
return NS_OK; |
| 167 |
} |
172 |
} |
| 168 |
|
173 |
|
| 169 |
nsresult |
174 |
nsresult |
| 170 |
nsDataHandler::ParseURI(nsCString& spec, |
175 |
nsDataHandler::ParseURI(nsCString& spec, |
| 171 |
nsCString& contentType, |
176 |
nsCString& contentType, |
| 172 |
nsCString& contentCharset, |
177 |
nsCString& contentCharset, |
| 173 |
PRBool& isBase64, |
178 |
PRBool& isBase64, |
| 174 |
nsCString& dataBuffer) { |
179 |
nsCString& dataBuffer, |
|
|
180 |
nsCString& hashRef) { |
| 175 |
isBase64 = PR_FALSE; |
181 |
isBase64 = PR_FALSE; |
| 176 |
|
182 |
|
| 177 |
// move past "data:" |
183 |
// move past "data:" |
| 178 |
char *buffer = (char *) PL_strcasestr(spec.BeginWriting(), "data:"); |
184 |
char *buffer = (char *) PL_strcasestr(spec.BeginWriting(), "data:"); |
| 179 |
if (!buffer) { |
185 |
if (!buffer) { |
| 180 |
// malformed uri |
186 |
// malformed uri |
| 181 |
return NS_ERROR_MALFORMED_URI; |
187 |
return NS_ERROR_MALFORMED_URI; |
| 182 |
} |
188 |
} |
|
Lines 225-236
nsDataHandler::ParseURI(nsCString& spec,
|
Link Here
|
|---|
|
| 225 |
|
231 |
|
| 226 |
*comma = ','; |
232 |
*comma = ','; |
| 227 |
if (isBase64) |
233 |
if (isBase64) |
| 228 |
*base64 = ';'; |
234 |
*base64 = ';'; |
| 229 |
|
235 |
|
| 230 |
contentType.StripWhitespace(); |
236 |
contentType.StripWhitespace(); |
| 231 |
contentCharset.StripWhitespace(); |
237 |
contentCharset.StripWhitespace(); |
| 232 |
|
238 |
|
| 233 |
dataBuffer.Assign(comma + 1); |
239 |
// Split encoded data from terminal "#ref" (if present) |
|
|
240 |
char *data = comma + 1; |
| 241 |
char *hash = strchr(data, '#'); |
| 242 |
PRUint32 dataLen; |
| 243 |
if (!hash) { |
| 244 |
dataBuffer.Assign(data); |
| 245 |
hashRef.Truncate(); |
| 246 |
} else { |
| 247 |
dataBuffer.Assign(data, hash - data); |
| 248 |
hashRef.Assign(hash); |
| 249 |
} |
| 234 |
|
250 |
|
| 235 |
return NS_OK; |
251 |
return NS_OK; |
| 236 |
} |
252 |
} |