Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: url/third_party/mozilla/url_parse.cc

Issue 23526048: Support URL fragment resolution againt non-hierarchical schemes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, Parsed* parsed) {
459 // Get the non-path and non-scheme parts of the URL out of the way, we never 459 // Get the non-path and non-scheme parts of the URL out of the way, we never
460 // use them. 460 // use them.
461 parsed->username.reset(); 461 parsed->username.reset();
462 parsed->password.reset(); 462 parsed->password.reset();
463 parsed->host.reset(); 463 parsed->host.reset();
464 parsed->port.reset(); 464 parsed->port.reset();
465 parsed->path.reset();
465 parsed->query.reset(); 466 parsed->query.reset();
466 parsed->ref.reset(); 467 parsed->ref.reset();
467 468
468 // Strip leading & trailing spaces and control characters. 469 // Strip leading & trailing spaces and control characters.
469 int begin = 0; 470 int begin = 0;
470 TrimURL(spec, &begin, &spec_len); 471 TrimURL(spec, &begin, &spec_len);
471 472
472 // Handle empty specs or ones that contain only whitespace or control chars. 473 // Handle empty specs or ones that contain only whitespace or control chars.
473 if (begin == spec_len) { 474 if (begin == spec_len) {
474 parsed->scheme.reset(); 475 parsed->scheme.reset();
475 parsed->path.reset(); 476 parsed->path.reset();
476 return; 477 return;
477 } 478 }
478 479
479 // Extract the scheme, with the path being everything following. We also 480 // Extract the scheme, with the path being everything following. We also
480 // handle the case where there is no scheme. 481 // handle the case where there is no scheme.
481 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) { 482 if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) {
482 // Offset the results since we gave ExtractScheme a substring. 483 // Offset the results since we gave ExtractScheme a substring.
483 parsed->scheme.begin += begin; 484 parsed->scheme.begin += begin;
485 begin = parsed->scheme.end() + 1;
486 } else {
487 parsed->scheme.reset();
488 }
484 489
485 // For compatability with the standard URL parser, we treat no path as 490 if (begin == spec_len)
486 // -1, rather than having a length of 0 (we normally wouldn't care so 491 return;
487 // much for these non-standard URLs). 492 DCHECK_LT(begin, spec_len);
488 if (parsed->scheme.end() == spec_len - 1) 493
489 parsed->path.reset(); 494 ParsePath(spec,
490 else 495 MakeRange(begin, spec_len),
491 parsed->path = MakeRange(parsed->scheme.end() + 1, spec_len); 496 &parsed->path,
492 } else { 497 &parsed->query,
493 // No scheme found, just path. 498 &parsed->ref);
494 parsed->scheme.reset();
495 parsed->path = MakeRange(begin, spec_len);
496 }
497 } 499 }
498 500
499 template<typename CHAR> 501 template<typename CHAR>
500 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) { 502 void DoParseMailtoURL(const CHAR* spec, int spec_len, Parsed* parsed) {
501 DCHECK(spec_len >= 0); 503 DCHECK(spec_len >= 0);
502 504
503 // Get the non-path and non-scheme parts of the URL out of the way, we never 505 // Get the non-path and non-scheme parts of the URL out of the way, we never
504 // use them. 506 // use them.
505 parsed->username.reset(); 507 parsed->username.reset();
506 parsed->password.reset(); 508 parsed->password.reset();
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 return ref.begin; // Back over delimiter. 787 return ref.begin; // Back over delimiter.
786 788
787 // When there is a ref and we get here, the component we wanted was before 789 // When there is a ref and we get here, the component we wanted was before
788 // this and not found, so we always know the beginning of the ref is right. 790 // this and not found, so we always know the beginning of the ref is right.
789 return ref.begin - 1; // Don't want delimiter counted. 791 return ref.begin - 1; // Don't want delimiter counted.
790 } 792 }
791 793
792 return cur; 794 return cur;
793 } 795 }
794 796
797 Component Parsed::Content() const {
798 const int begin = CountCharactersBefore(USERNAME, false);
799 const int len = Length() - begin;
800 // For compatability with the standard URL parser, we treat no content as
801 // -1, rather than having a length of 0 (we normally wouldn't care so
802 // much for these non-standard URLs).
803 return len ? Component(begin, len) : Component();
804 }
805
795 bool ExtractScheme(const char* url, int url_len, Component* scheme) { 806 bool ExtractScheme(const char* url, int url_len, Component* scheme) {
796 return DoExtractScheme(url, url_len, scheme); 807 return DoExtractScheme(url, url_len, scheme);
797 } 808 }
798 809
799 bool ExtractScheme(const base::char16* url, int url_len, Component* scheme) { 810 bool ExtractScheme(const base::char16* url, int url_len, Component* scheme) {
800 return DoExtractScheme(url, url_len, scheme); 811 return DoExtractScheme(url, url_len, scheme);
801 } 812 }
802 813
803 // This handles everything that may be an authority terminator, including 814 // This handles everything that may be an authority terminator, including
804 // backslash. For special backslash handling see DoParseAfterScheme. 815 // backslash. For special backslash handling see DoParseAfterScheme.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } 925 }
915 926
916 void ParseAfterScheme(const base::char16* spec, 927 void ParseAfterScheme(const base::char16* spec,
917 int spec_len, 928 int spec_len,
918 int after_scheme, 929 int after_scheme,
919 Parsed* parsed) { 930 Parsed* parsed) {
920 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); 931 DoParseAfterScheme(spec, spec_len, after_scheme, parsed);
921 } 932 }
922 933
923 } // namespace url_parse 934 } // namespace url_parse
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698