Percent-decode fragments before using them for SVG references

We were using the "raw" form of the fragment, meaning that any percent-
encoded fragments would not resolve correctly.

Bug: 779420
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ic091e775589fd59d25ad1878115f2ad2593bc733
Reviewed-on: https://chromium-review.googlesource.com/746885
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#512895}
diff --git a/third_party/WebKit/LayoutTests/svg/custom/fill-url-percent-encoding-expected.html b/third_party/WebKit/LayoutTests/svg/custom/fill-url-percent-encoding-expected.html
new file mode 100644
index 0000000..f718ea6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/custom/fill-url-percent-encoding-expected.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<div style="width: 100px; height: 100px; background-color: green"></div>
diff --git a/third_party/WebKit/LayoutTests/svg/custom/fill-url-percent-encoding.html b/third_party/WebKit/LayoutTests/svg/custom/fill-url-percent-encoding.html
new file mode 100644
index 0000000..2fc1814
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/custom/fill-url-percent-encoding.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<svg>
+  <defs>
+    <linearGradient id="foo">
+      <stop stop-color="green"/>
+    </linearGradient>
+  </defs>
+  <rect width="100" height="100" fill="url(#%66%6f%6f) red"/>
+</svg>
diff --git a/third_party/WebKit/LayoutTests/svg/custom/use-href-percent-encoding-expected.html b/third_party/WebKit/LayoutTests/svg/custom/use-href-percent-encoding-expected.html
new file mode 100644
index 0000000..f718ea6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/custom/use-href-percent-encoding-expected.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<div style="width: 100px; height: 100px; background-color: green"></div>
diff --git a/third_party/WebKit/LayoutTests/svg/custom/use-href-percent-encoding.html b/third_party/WebKit/LayoutTests/svg/custom/use-href-percent-encoding.html
new file mode 100644
index 0000000..f085948
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/svg/custom/use-href-percent-encoding.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<svg xmlns="http://www.w3.org/2000/svg">
+  <symbol id="желтый">
+    <rect width="50" height="100" fill="green"/>
+  </symbol>
+  <symbol id="зеленый">
+    <rect width="50" height="100" fill="green"/>
+  </symbol>
+  <use href="#желтый"/>
+  <use href="#%D0%B7%D0%B5%D0%BB%D0%B5%D0%BD%D1%8B%D0%B9" x="50"/>
+</svg>
diff --git a/third_party/WebKit/Source/core/svg/SVGURIReference.cpp b/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
index ecedcc1..e5c9e8a 100644
--- a/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGURIReference.cpp
@@ -88,11 +88,10 @@
 }
 
 AtomicString SVGURLReferenceResolver::FragmentIdentifier() const {
-  // If this is a "fragment-only" URL, then the reference is always local, so
-  // just return what's after the '#' as the fragment.
-  if (is_local_)
-    return AtomicString(relative_url_.Substring(1));
-  return AtomicString(AbsoluteUrl().FragmentIdentifier());
+  // Use KURL's FragmentIdentifier to ensure that we're handling the
+  // fragment in a consistent manner.
+  return AtomicString(
+      DecodeURLEscapeSequences(AbsoluteUrl().FragmentIdentifier()));
 }
 
 AtomicString SVGURIReference::FragmentIdentifierFromIRIString(
diff --git a/third_party/WebKit/Source/core/svg/SVGUseElement.cpp b/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
index b4ea6fa..3d1e8ac2 100644
--- a/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
@@ -305,7 +305,8 @@
 Element* SVGUseElement::ResolveTargetElement(ObserveBehavior observe_behavior) {
   if (!element_url_.HasFragmentIdentifier())
     return nullptr;
-  AtomicString element_identifier(element_url_.FragmentIdentifier());
+  AtomicString element_identifier(
+      DecodeURLEscapeSequences(element_url_.FragmentIdentifier()));
   if (!IsStructurallyExternal()) {
     if (observe_behavior == kDontAddObserver)
       return GetTreeScope().getElementById(element_identifier);