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 begin = 0; |
470 TrimURL(spec, &begin, &spec_len); | 473 TrimURL(spec, &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 (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 |
479 // Extract the scheme, with the path being everything following. We also | 482 // Extract the scheme, with the path being everything following. We also |
480 // handle the case where there is no scheme. | 483 // handle the case where there is no scheme. |
481 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { | 484 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { |
482 // Offset the results since we gave ExtractScheme a substring. | 485 // Offset the results since we gave ExtractScheme a substring. |
483 parsed->scheme.begin += begin; | 486 parsed->scheme.begin += begin; |
487 begin = parsed->scheme.end() + 1; | |
brettw
2013/11/20 00:03:51
I'd rather introduce a new after_scheme variable h
joth
2013/11/21 00:08:45
Done.
| |
488 } else { | |
489 parsed->scheme.reset(); | |
490 } | |
484 | 491 |
485 // For compatability with the standard URL parser, we treat no path as | 492 if (begin == spec_len) |
486 // -1, rather than having a length of 0 (we normally wouldn't care so | 493 return; |
487 // much for these non-standard URLs). | 494 DCHECK_LT(begin, spec_len); |
488 if (parsed->scheme.end() == spec_len - 1) | 495 |
489 parsed->path.reset(); | 496 ParsePath(spec, |
490 else | 497 MakeRange(begin, spec_len), |
491 parsed->path = MakeRange(parsed->scheme.end() + 1, spec_len); | 498 &parsed->path, |
492 } else { | 499 &parsed->query, |
493 // No scheme found, just path. | 500 &parsed->ref); |
494 parsed->scheme.reset(); | |
495 parsed->path = MakeRange(begin, spec_len); | |
496 } | |
497 } | 501 } |
498 | 502 |
499 template<typename CHAR> | 503 template<typename CHAR> |
500 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { | 504 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { |
501 DCHECK(spec_len >= 0); | 505 DCHECK(spec_len >= 0); |
502 | 506 |
503 // Get the non-path and non-scheme parts of the URL out of the way, we never | 507 // Get the non-path and non-scheme parts of the URL out of the way, we never |
504 // use them. | 508 // use them. |
505 parsed->username.reset(); | 509 parsed->username.reset(); |
506 parsed->password.reset(); | 510 parsed->password.reset(); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 } | 872 } |
869 | 873 |
870 void ParseStandardURL(const char* url, int url_len, Parsed* parsed) { | 874 void ParseStandardURL(const char* url, int url_len, Parsed* parsed) { |
871 DoParseStandardURL(url, url_len, parsed); | 875 DoParseStandardURL(url, url_len, parsed); |
872 } | 876 } |
873 | 877 |
874 void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { | 878 void ParseStandardURL(const base::char16* url, int url_len, Parsed* parsed) { |
875 DoParseStandardURL(url, url_len, parsed); | 879 DoParseStandardURL(url, url_len, parsed); |
876 } | 880 } |
877 | 881 |
878 void ParsePathURL(const char* url, int url_len, Parsed* parsed) { | 882 void ParsePathURL(const char* url, |
879 DoParsePathURL(url, url_len, parsed); | 883 int url_len, |
884 bool trim_path_end, | |
885 Parsed* parsed) { | |
886 DoParsePathURL(url, url_len, trim_path_end, parsed); | |
880 } | 887 } |
881 | 888 |
882 void ParsePathURL(const base::char16* url, int url_len, Parsed* parsed) { | 889 void ParsePathURL(const base::char16* url, |
883 DoParsePathURL(url, url_len, parsed); | 890 int url_len, |
891 bool trim_path_end, | |
892 Parsed* parsed) { | |
893 DoParsePathURL(url, url_len, trim_path_end, parsed); | |
884 } | 894 } |
885 | 895 |
886 void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { | 896 void ParseFileSystemURL(const char* url, int url_len, Parsed* parsed) { |
887 DoParseFileSystemURL(url, url_len, parsed); | 897 DoParseFileSystemURL(url, url_len, parsed); |
888 } | 898 } |
889 | 899 |
890 void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed) { | 900 void ParseFileSystemURL(const base::char16* url, int url_len, Parsed* parsed) { |
891 DoParseFileSystemURL(url, url_len, parsed); | 901 DoParseFileSystemURL(url, url_len, parsed); |
892 } | 902 } |
893 | 903 |
(...skipping 29 matching lines...) Expand all Loading... | |
923 } | 933 } |
924 | 934 |
925 void ParseAfterScheme(const base::char16* spec, | 935 void ParseAfterScheme(const base::char16* spec, |
926 int spec_len, | 936 int spec_len, |
927 int after_scheme, | 937 int after_scheme, |
928 Parsed* parsed) { | 938 Parsed* parsed) { |
929 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); | 939 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); |
930 } | 940 } |
931 | 941 |
932 } // namespace url_parse | 942 } // namespace url_parse |
OLD | NEW |