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 |