OLD | NEW |
1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 url_canon::CharsetConverter* charset_converter, | 229 url_canon::CharsetConverter* charset_converter, |
230 url_canon::CanonOutput* output, | 230 url_canon::CanonOutput* output, |
231 url_parse::Parsed* output_parsed) { | 231 url_parse::Parsed* output_parsed) { |
232 // Remove any whitespace from the middle of the relative URL, possibly | 232 // Remove any whitespace from the middle of the relative URL, possibly |
233 // copying to the new buffer. | 233 // copying to the new buffer. |
234 url_canon::RawCanonOutputT<CHAR> whitespace_buffer; | 234 url_canon::RawCanonOutputT<CHAR> whitespace_buffer; |
235 int relative_length; | 235 int relative_length; |
236 const CHAR* relative = RemoveURLWhitespace(in_relative, in_relative_length, | 236 const CHAR* relative = RemoveURLWhitespace(in_relative, in_relative_length, |
237 &whitespace_buffer, | 237 &whitespace_buffer, |
238 &relative_length); | 238 &relative_length); |
| 239 bool base_is_authority_based = false; |
| 240 bool base_is_hierarchical = false; |
| 241 if (base_spec && |
| 242 base_parsed.scheme.is_nonempty()) { |
| 243 int after_scheme = base_parsed.scheme.end() + 1; // Skip past the colon. |
| 244 int num_slashes = url_parse::CountConsecutiveSlashes( |
| 245 base_spec, after_scheme, base_spec_len); |
| 246 base_is_authority_based = num_slashes > 1; |
| 247 base_is_hierarchical = num_slashes > 0; |
| 248 } |
239 | 249 |
240 // See if our base URL should be treated as "standard". | |
241 bool standard_base_scheme = | 250 bool standard_base_scheme = |
242 base_parsed.scheme.is_nonempty() && | 251 base_parsed.scheme.is_nonempty() && |
243 DoIsStandard(base_spec, base_parsed.scheme); | 252 DoIsStandard(base_spec, base_parsed.scheme); |
244 | 253 |
245 bool is_relative; | 254 bool is_relative; |
246 url_parse::Component relative_component; | 255 url_parse::Component relative_component; |
247 if (!url_canon::IsRelativeURL(base_spec, base_parsed, | 256 if (!url_canon::IsRelativeURL(base_spec, base_parsed, |
248 relative, relative_length, | 257 relative, relative_length, |
249 standard_base_scheme, | 258 (base_is_hierarchical || standard_base_scheme), |
250 &is_relative, | 259 &is_relative, |
251 &relative_component)) { | 260 &relative_component)) { |
252 // Error resolving. | 261 // Error resolving. |
253 return false; | 262 return false; |
254 } | 263 } |
255 | 264 |
256 if (is_relative) { | 265 if (is_relative && base_is_authority_based && !standard_base_scheme) { |
| 266 url_parse::Parsed base_parsed_authority; |
| 267 |
| 268 // Pretend for a moment that |base_spec| is a standard URL. Normally |
| 269 // non-standard URLs are treated as PathURLs, but if the base has an |
| 270 // authority we would like to preserve it. |
| 271 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority); |
| 272 if (base_parsed_authority.host.is_nonempty()) { |
| 273 bool did_resolve_succeed = |
| 274 url_canon::ResolveRelativeURL(base_spec, base_parsed_authority, |
| 275 false, relative, |
| 276 relative_component, charset_converter, |
| 277 output, output_parsed); |
| 278 // The output_parsed is incorrect at this point (because it was built |
| 279 // based on base_parsed_authority instead of base_parsed) and needs to be |
| 280 // re-created. |
| 281 ParsePathURL(output->data(), output->length(), output_parsed); |
| 282 return did_resolve_succeed; |
| 283 } |
| 284 } else if (is_relative) { |
257 // Relative, resolve and canonicalize. | 285 // Relative, resolve and canonicalize. |
258 bool file_base_scheme = base_parsed.scheme.is_nonempty() && | 286 bool file_base_scheme = base_parsed.scheme.is_nonempty() && |
259 DoCompareSchemeComponent(base_spec, base_parsed.scheme, kFileScheme); | 287 DoCompareSchemeComponent(base_spec, base_parsed.scheme, kFileScheme); |
260 return url_canon::ResolveRelativeURL(base_spec, base_parsed, | 288 return url_canon::ResolveRelativeURL(base_spec, base_parsed, |
261 file_base_scheme, relative, | 289 file_base_scheme, relative, |
262 relative_component, charset_converter, | 290 relative_component, charset_converter, |
263 output, output_parsed); | 291 output, output_parsed); |
264 } | 292 } |
265 | 293 |
266 // Not relative, canonicalize the input. | 294 // Not relative, canonicalize the input. |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 return DoCompareSchemeComponent(spec, component, compare_to); | 610 return DoCompareSchemeComponent(spec, component, compare_to); |
583 } | 611 } |
584 | 612 |
585 bool CompareSchemeComponent(const char16* spec, | 613 bool CompareSchemeComponent(const char16* spec, |
586 const url_parse::Component& component, | 614 const url_parse::Component& component, |
587 const char* compare_to) { | 615 const char* compare_to) { |
588 return DoCompareSchemeComponent(spec, component, compare_to); | 616 return DoCompareSchemeComponent(spec, component, compare_to); |
589 } | 617 } |
590 | 618 |
591 } // namespace url_util | 619 } // namespace url_util |
OLD | NEW |