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

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: really fix 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 | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »
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..434b7c8a8d73d1cb137afb4364199732baf14e2b 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -36,6 +36,8 @@ inline bool DoLowerCaseEqualsASCII(Iter a_begin, Iter a_end, const char* b) {
return *b == 0;
}
+bool g_kurl_compat_mode = false;
+
const int kNumStandardURLSchemes = 8;
const char* kStandardURLSchemes[kNumStandardURLSchemes] = {
"http",
@@ -233,6 +235,30 @@ bool DoResolveRelative(const char* base_spec,
(base_is_hierarchical || standard_base_scheme),
&is_relative,
&relative_component)) {
+ if (g_kurl_compat_mode && 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;
}
@@ -376,6 +402,10 @@ void Shutdown() {
}
}
+void SetKURLCompatMode(bool enable) {
+ g_kurl_compat_mode = enable;
+}
+
void AddStandardScheme(const char* new_scheme) {
// If this assert triggers, it means you've called AddStandardScheme after
// LockStandardSchemes have been called (see the header file for
« no previous file with comments | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698