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

Side by Side Diff: url/url_util.cc

Issue 23468003: Allow fragments to resolve relatively against any scheme (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: actually seems to work 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 | « no previous file | url/url_util_unittest.cc » ('j') | url/url_util_unittest.cc » ('J')
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 #include "url/url_util.h" 5 #include "url/url_util.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 base_parsed.scheme.is_nonempty() && 226 base_parsed.scheme.is_nonempty() &&
227 DoIsStandard(base_spec, base_parsed.scheme); 227 DoIsStandard(base_spec, base_parsed.scheme);
228 228
229 bool is_relative; 229 bool is_relative;
230 url_parse::Component relative_component; 230 url_parse::Component relative_component;
231 if (!url_canon::IsRelativeURL(base_spec, base_parsed, 231 if (!url_canon::IsRelativeURL(base_spec, base_parsed,
232 relative, relative_length, 232 relative, relative_length,
233 (base_is_hierarchical || standard_base_scheme), 233 (base_is_hierarchical || standard_base_scheme),
234 &is_relative, 234 &is_relative,
235 &relative_component)) { 235 &relative_component)) {
236 if (relative_length && *relative == '#') {
237 // Allow a fragemnt on its own to resolve against any base URL (even non-
238 // hierarchical). First attempt to re-parse the path portion of the base
239 // URL using a more relaxed algorithm for matching fragment sections.
240 url_parse::Parsed base_reparsed = base_parsed;
241 if (base_reparsed.path.is_valid() &&
242 !base_reparsed.query.is_valid() &&
243 !base_reparsed.ref.is_valid()) {
244 const int path_end = base_reparsed.path.end();
245 for (int i = base_reparsed.path.begin; i < path_end; ++i) {
246 if (base_spec[i] == '#') {
247 base_reparsed.path.len = i - base_reparsed.path.begin;
248 base_reparsed.ref = url_parse::MakeRange(i, path_end);
249 break;
250 }
251 }
252 }
253 return url_canon::ResolveRelativeURL(base_spec, base_reparsed,
254 false, relative,
255 url_parse::MakeRange(0, relative_leng th),
256 charset_converter,
257 output, output_parsed);
258 }
236 // Error resolving. 259 // Error resolving.
237 return false; 260 return false;
238 } 261 }
239 262
240 // Pretend for a moment that |base_spec| is a standard URL. Normally 263 // Pretend for a moment that |base_spec| is a standard URL. Normally
241 // non-standard URLs are treated as PathURLs, but if the base has an 264 // non-standard URLs are treated as PathURLs, but if the base has an
242 // authority we would like to preserve it. 265 // authority we would like to preserve it.
243 if (is_relative && base_is_authority_based && !standard_base_scheme) { 266 if (is_relative && base_is_authority_based && !standard_base_scheme) {
244 url_parse::Parsed base_parsed_authority; 267 url_parse::Parsed base_parsed_authority;
245 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority); 268 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 return DoCompareSchemeComponent(spec, component, compare_to); 608 return DoCompareSchemeComponent(spec, component, compare_to);
586 } 609 }
587 610
588 bool CompareSchemeComponent(const base::char16* spec, 611 bool CompareSchemeComponent(const base::char16* spec,
589 const url_parse::Component& component, 612 const url_parse::Component& component,
590 const char* compare_to) { 613 const char* compare_to) {
591 return DoCompareSchemeComponent(spec, component, compare_to); 614 return DoCompareSchemeComponent(spec, component, compare_to);
592 } 615 }
593 616
594 } // namespace url_util 617 } // namespace url_util
OLDNEW
« no previous file with comments | « no previous file | url/url_util_unittest.cc » ('j') | url/url_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698