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

Side by Side Diff: url/url_canon_relative.cc

Issue 23526048: Support URL fragment resolution againt non-hierarchical schemes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clea 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
« no previous file with comments | « url/url_canon_pathurl.cc ('k') | url/url_canon_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, &url_parsed);
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 // |url| has no scheme. Check the other extreme: is it a bare fragment.
109 bool url_is_ref_only = url_parsed.ref.is_valid() &&
110 url_parsed.CountCharactersBefore(url_parse::Parsed::REF, true) ==
111 url_parsed.CountCharactersBefore(url_parse::Parsed::SCHEME, false);
112 if (!url_is_ref_only && !is_base_hierarchical) {
113 // Don't allow relative URLs if the base scheme doesn't support it.
107 return false; 114 return false;
115 }
108 116
109 *relative_component = url_parse::MakeRange(begin, url_len); 117 *relative_component = url_parse::MakeRange(begin, url_len);
110 *is_relative = true; 118 *is_relative = true;
111 return true; 119 return true;
112 } 120 }
113 121
114 // If the scheme isn't valid, then it's relative. 122 // If the scheme isn't valid, then it's relative.
115 int scheme_end = scheme.end(); 123 int scheme_end = scheme.end();
116 for (int i = scheme.begin; i < scheme_end; i++) { 124 for (int i = scheme.begin; i < scheme_end; i++) {
117 if (!CanonicalSchemeChar(url[i])) { 125 if (!CanonicalSchemeChar(url[i])) {
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 const url_parse::Component& relative_component, 553 const url_parse::Component& relative_component,
546 CharsetConverter* query_converter, 554 CharsetConverter* query_converter,
547 CanonOutput* output, 555 CanonOutput* output,
548 url_parse::Parsed* out_parsed) { 556 url_parse::Parsed* out_parsed) {
549 return DoResolveRelativeURL<base::char16>( 557 return DoResolveRelativeURL<base::char16>(
550 base_url, base_parsed, base_is_file, relative_url, 558 base_url, base_parsed, base_is_file, relative_url,
551 relative_component, query_converter, output, out_parsed); 559 relative_component, query_converter, output, out_parsed);
552 } 560 }
553 561
554 } // namespace url_canon 562 } // namespace url_canon
OLDNEW
« no previous file with comments | « url/url_canon_pathurl.cc ('k') | url/url_canon_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698