OLD | NEW |
1 /* Based on nsURLParsers.cc from Mozilla | 1 /* Based on nsURLParsers.cc from Mozilla |
2 * ------------------------------------- | 2 * ------------------------------------- |
3 * The contents of this file are subject to the Mozilla Public License Version | 3 * The contents of this file are subject to the Mozilla Public License Version |
4 * 1.1 (the "License"); you may not use this file except in compliance with | 4 * 1.1 (the "License"); you may not use this file except in compliance with |
5 * the License. You may obtain a copy of the License at | 5 * the License. You may obtain a copy of the License at |
6 * http://www.mozilla.org/MPL/ | 6 * http://www.mozilla.org/MPL/ |
7 * | 7 * |
8 * Software distributed under the License is distributed on an "AS IS" basis, | 8 * Software distributed under the License is distributed on an "AS IS" basis, |
9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
10 * for the specific language governing rights and limitations under the | 10 * for the specific language governing rights and limitations under the |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 ++inner_path_end; | 448 ++inner_path_end; |
449 parsed->path.begin = inner_path_end; | 449 parsed->path.begin = inner_path_end; |
450 int new_inner_path_length = inner_path_end - inner_parsed.path.begin; | 450 int new_inner_path_length = inner_path_end - inner_parsed.path.begin; |
451 parsed->path.len = inner_parsed.path.len - new_inner_path_length; | 451 parsed->path.len = inner_parsed.path.len - new_inner_path_length; |
452 parsed->inner_parsed()->path.len = new_inner_path_length; | 452 parsed->inner_parsed()->path.len = new_inner_path_length; |
453 } | 453 } |
454 | 454 |
455 // Initializes a path URL which is merely a scheme followed by a path. Examples | 455 // Initializes a path URL which is merely a scheme followed by a path. Examples |
456 // include "about:foo" and "javascript:alert('bar');" | 456 // include "about:foo" and "javascript:alert('bar');" |
457 template<typename CHAR> | 457 template<typename CHAR> |
458 void DoParsePathURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 458 void DoParsePathURL(const CHAR* spec, int spec_len, |
| 459 bool trim_path_end, |
| 460 Parsed* parsed) { |
459 // Get the non-path and non-scheme parts of the URL out of the way, we never | 461 // Get the non-path and non-scheme parts of the URL out of the way, we never |
460 // use them. | 462 // use them. |
461 parsed->username.reset(); | 463 parsed->username.reset(); |
462 parsed->password.reset(); | 464 parsed->password.reset(); |
463 parsed->host.reset(); | 465 parsed->host.reset(); |
464 parsed->port.reset(); | 466 parsed->port.reset(); |
| 467 parsed->path.reset(); |
465 parsed->query.reset(); | 468 parsed->query.reset(); |
466 parsed->ref.reset(); | 469 parsed->ref.reset(); |
467 | 470 |
468 // Strip leading & trailing spaces and control characters. | 471 // Strip leading & trailing spaces and control characters. |
469 int begin = 0; | 472 int scheme_begin = 0; |
470 TrimURL(spec, &begin, &spec_len); | 473 TrimURL(spec, &scheme_begin, &spec_len, trim_path_end); |
471 | 474 |
472 // Handle empty specs or ones that contain only whitespace or control chars. | 475 // Handle empty specs or ones that contain only whitespace or control chars. |
473 if (begin == spec_len) { | 476 if (scheme_begin == spec_len) { |
474 parsed->scheme.reset(); | 477 parsed->scheme.reset(); |
475 parsed->path.reset(); | 478 parsed->path.reset(); |
476 return; | 479 return; |
477 } | 480 } |
478 | 481 |
| 482 int path_begin; |
479 // Extract the scheme, with the path being everything following. We also | 483 // Extract the scheme, with the path being everything following. We also |
480 // handle the case where there is no scheme. | 484 // handle the case where there is no scheme. |
481 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { | 485 if (ExtractScheme(&spec[scheme_begin], spec_len - scheme_begin, |
| 486 &parsed->scheme)) { |
482 // Offset the results since we gave ExtractScheme a substring. | 487 // Offset the results since we gave ExtractScheme a substring. |
483 parsed->scheme.begin += begin; | 488 parsed->scheme.begin += scheme_begin; |
| 489 path_begin = parsed->scheme.end() + 1; |
| 490 } else { |
| 491 // No scheme case. |
| 492 parsed->scheme.reset(); |
| 493 path_begin = scheme_begin; |
| 494 } |
484 | 495 |
485 // For compatability with the standard URL parser, we treat no path as | 496 if (path_begin == spec_len) |
486 // -1, rather than having a length of 0 (we normally wouldn't care so | 497 return; |
487 // much for these non-standard URLs). | 498 DCHECK_LT(path_begin, spec_len); |
488 if (parsed->scheme.end() == spec_len - 1) | 499 |
489 parsed->path.reset(); | 500 ParsePath(spec, |
490 else | 501 MakeRange(path_begin, spec_len), |
491 parsed->path = MakeRange(parsed->scheme.end() + 1, spec_len); | 502 &parsed->path, |
492 } else { | 503 &parsed->query, |
493 // No scheme found, just path. | 504 &parsed->ref); |
494 parsed->scheme.reset(); | |
495 parsed->path = MakeRange(begin, spec_len); | |
496 } | |
497 } | 505 } |
498 | 506 |
499 template<typename CHAR> | 507 template<typename CHAR> |
500 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 508 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
501 DCHECK(spec_len >= 0); | 509 DCHECK(spec_len >= 0); |
502 | 510 |
503 // Get the non-path and non-scheme parts of the URL out of the way, we never | 511 // Get the non-path and non-scheme parts of the URL out of the way, we never |
504 // use them. | 512 // use them. |
505 parsed->username.reset(); | 513 parsed->username.reset(); |
506 parsed->password.reset(); | 514 parsed->password.reset(); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 } | 876 } |
869 | 877 |
870 void ParseStandardURL(const char* url, int url_len, Parsed* parsed) { | 878 void ParseStandardURL(const char* url, int url_len, Parsed* parsed) { |
871 DoParseStandardURL(url, url_len, parsed); | 879 DoParseStandardURL(url, url_len, parsed); |
872 } | 880 } |
873 | 881 |
874 void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { | 882 void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { |
875 DoParseStandardURL(url, url_len, parsed); | 883 DoParseStandardURL(url, url_len, parsed); |
876 } | 884 } |
877 | 885 |
878 void ParsePathURL(const char* url, int url_len, Parsed* parsed) { | 886 void ParsePathURL(const char* url, |
879 DoParsePathURL(url, url_len, parsed); | 887 int url_len, |
| 888 bool trim_path_end, |
| 889 Parsed* parsed) { |
| 890 DoParsePathURL(url, url_len, trim_path_end, parsed); |
880 } | 891 } |
881 | 892 |
882 void ParsePathURL(const base::char16* url, int url_len, Parsed* parsed) { | 893 void ParsePathURL(const base::char16* url, |
883 DoParsePathURL(url, url_len, parsed); | 894 int url_len, |
| 895 bool trim_path_end, |
| 896 Parsed* parsed) { |
| 897 DoParsePathURL(url, url_len, trim_path_end, parsed); |
884 } | 898 } |
885 | 899 |
886 void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { | 900 void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { |
887 DoParseFileSystemURL(url, url_len, parsed); | 901 DoParseFileSystemURL(url, url_len, parsed); |
888 } | 902 } |
889 | 903 |
890 void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed) { | 904 void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed) { |
891 DoParseFileSystemURL(url, url_len, parsed); | 905 DoParseFileSystemURL(url, url_len, parsed); |
892 } | 906 } |
893 | 907 |
(...skipping 29 matching lines...) Expand all Loading... |
923 } | 937 } |
924 | 938 |
925 void ParseAfterScheme(const base::char16* spec, | 939 void ParseAfterScheme(const base::char16* spec, |
926 int spec_len, | 940 int spec_len, |
927 int after_scheme, | 941 int after_scheme, |
928 Parsed* parsed) { | 942 Parsed* parsed) { |
929 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 943 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
930 } | 944 } |
931 | 945 |
932 } // namespace url_parse | 946 } // namespace url_parse |
OLD | NEW |