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

Side by Side Diff: url/url_canon_relative.cc

Issue 23835019: Support URL fragment resolution againt non-hierarchical schemes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: actually restore PS4 this time Created 7 years, 1 month 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Canonicalizer functions for working with and resolving relative URLs. 5 // Canonicalizer functions for working with and resolving relative URLs.
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "url/url_canon.h" 8 #include "url/url_canon.h"
9 #include "url/url_canon_internal.h" 9 #include "url/url_canon_internal.h"
10 #include "url/url_file.h" 10 #include "url/url_file.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // shashes should be treated a a relative URL with a hostname. 93 // shashes should be treated a a relative URL with a hostname.
94 if (url_parse::DoesBeginWindowsDriveSpec(url, begin, url_len) || 94 if (url_parse::DoesBeginWindowsDriveSpec(url, begin, url_len) ||
95 url_parse::DoesBeginUNCPath(url, begin, url_len, true)) 95 url_parse::DoesBeginUNCPath(url, begin, url_len, true))
96 return true; 96 return true;
97 #endif // WIN32 97 #endif // WIN32
98 98
99 // See if we've got a scheme, if not, we know this is a relative URL. 99 // See if we've got a scheme, if not, we know this is a relative URL.
100 // BUT: Just because we have a scheme, doesn't make it absolute. 100 // BUT: Just because we have a scheme, doesn't make it absolute.
101 // "http:foo.html" is a relative URL with path "foo.html". If the scheme is 101 // "http:foo.html" is a relative URL with path "foo.html". If the scheme is
102 // empty, we treat it as relative (":foo") like IE does. 102 // empty, we treat it as relative (":foo") like IE does.
103 url_parse::Component scheme; 103 url_parse::Parsed url_parsed;
104 if (!url_parse::ExtractScheme(url, url_len, &scheme) || scheme.len == 0) { 104 url_parse::ParsePathURL(url, url_len, true, &url_parsed);
brettw 2013/11/20 00:03:51 This codepath is called a lot and ParsePathURL and
joth 2013/11/21 00:08:45 Done. Reverted to the scheme lookup to as it was
105 // Don't allow relative URLs if the base scheme doesn't support it. 105 const url_parse::Component& scheme = url_parsed.scheme;
106 if (!is_base_hierarchical) 106 const bool scheme_is_empty = !scheme.is_nonempty();
107 if (scheme_is_empty) {
108 // No scheme. See if is a bare fragment.
109 if (url_parsed.ref.is_valid() &&
110 url_parsed.CountCharactersBefore(url_parse::Parsed::REF, true) ==
111 url_parsed.CountCharactersBefore(url_parse::Parsed::SCHEME, false)) {
112 // |url| is a bare fragement. This can be resolved against any base.
113 } else if (!is_base_hierarchical) {
114 // Don't allow relative URLs if the base scheme doesn't support it.
107 return false; 115 return false;
116 }
108 117
109 *relative_component = url_parse::MakeRange(begin, url_len); 118 *relative_component = url_parse::MakeRange(begin, url_len);
110 *is_relative = true; 119 *is_relative = true;
111 return true; 120 return true;
112 } 121 }
113 122
114 // If the scheme isn't valid, then it's relative. 123 // If the scheme isn't valid, then it's relative.
115 int scheme_end = scheme.end(); 124 int scheme_end = scheme.end();
116 for (int i = scheme.begin; i < scheme_end; i++) { 125 for (int i = scheme.begin; i < scheme_end; i++) {
117 if (!CanonicalSchemeChar(url[i])) { 126 if (!CanonicalSchemeChar(url[i])) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 const url_parse::Component& relative_component, 556 const url_parse::Component& relative_component,
548 CharsetConverter* query_converter, 557 CharsetConverter* query_converter,
549 CanonOutput* output, 558 CanonOutput* output,
550 url_parse::Parsed* out_parsed) { 559 url_parse::Parsed* out_parsed) {
551 return DoResolveRelativeURL<base::char16>( 560 return DoResolveRelativeURL<base::char16>(
552 base_url, base_parsed, base_is_file, relative_url, 561 base_url, base_parsed, base_is_file, relative_url,
553 relative_component, query_converter, output, out_parsed); 562 relative_component, query_converter, output, out_parsed);
554 } 563 }
555 564
556 } // namespace url_canon 565 } // namespace url_canon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698