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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | url/url_util_unittest.cc » ('j') | url/url_util_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/url_util.cc
diff --git a/url/url_util.cc b/url/url_util.cc
index f16af98db85cc986a50af25630efa29da227d741..3b3943f314bcacd232050f2b945ed60a0fd8d640 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -233,6 +233,29 @@ bool DoResolveRelative(const char* base_spec,
(base_is_hierarchical || standard_base_scheme),
&is_relative,
&relative_component)) {
+ if (relative_length && *relative == '#') {
+ // Allow a fragemnt on its own to resolve against any base URL (even non-
+ // hierarchical). First attempt to re-parse the path portion of the base
+ // URL using a more relaxed algorithm for matching fragment sections.
+ url_parse::Parsed base_reparsed = base_parsed;
+ if (base_reparsed.path.is_valid() &&
+ !base_reparsed.query.is_valid() &&
+ !base_reparsed.ref.is_valid()) {
+ const int path_end = base_reparsed.path.end();
+ for (int i = base_reparsed.path.begin; i < path_end; ++i) {
+ if (base_spec[i] == '#') {
+ base_reparsed.path.len = i - base_reparsed.path.begin;
+ base_reparsed.ref = url_parse::MakeRange(i, path_end);
+ break;
+ }
+ }
+ }
+ return url_canon::ResolveRelativeURL(base_spec, base_reparsed,
+ false, relative,
+ url_parse::MakeRange(0, relative_length),
+ charset_converter,
+ output, output_parsed);
+ }
// Error resolving.
return false;
}
« 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