Work-around for URL fragments resolving against about:blank

Bug 10459904

The upstream review for this issue (http://crbug.com/291747) is complex
and will take time to land, so in meantime applying a smaller special
case workaround in android tree. This will be reverted when the fix from
trunk is ready.

Patch taken from http://crrev.com/23468003 PS2
https://codereview.chromium.org/23468003/diff/4001/url/url_util.cc

Change-Id: I57142c382c38e8161853b690c85c3a40990e2f75
diff --git a/url/url_util.cc b/url/url_util.cc
index f16af98..8a68702 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -233,6 +233,32 @@
                                 (base_is_hierarchical || standard_base_scheme),
                                 &is_relative,
                                 &relative_component)) {
+    // === START ===  android workaround for b/10459904
+    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);
+    }
+    // === END ===  android workaround for b/10459904
     // Error resolving.
     return false;
   }