Remove URL decoding in srcset handling
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2013 05:02:59 +0000 (05:02 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2013 05:02:59 +0000 (05:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121609

Patch by Yoav Weiss <yoav@yoav.ws> on 2013-09-19
Reviewed by Benjamin Poulain.

Source/WebCore:

Tests: fast/hidpi/image-srcset-question-mark.html
       fast/loader/image-src-question-mark.html

Removed URL decoding from src and srcset's handling algorithm, since they break encoded URLS.

* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseImagesWithScaleFromSrcSetAttribute):
(WebCore::bestFitSourceForImageAttributes):

LayoutTests:

These tests make sure that encoded URLs are properly handled, and especially URLs
with a question mark in them.

* fast/hidpi/image-srcset-question-mark-expected.txt: Added.
* fast/hidpi/image-srcset-question-mark.html: Added.
* fast/hidpi/resources/image?test.png: Added.
* fast/loader/image-src-question-mark-expected.txt: Added.
* fast/loader/image-src-question-mark.html: Added.
* fast/loader/resources/image?test.png: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156140 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/hidpi/image-srcset-question-mark-expected.txt [new file with mode: 0644]
LayoutTests/fast/hidpi/image-srcset-question-mark.html [new file with mode: 0644]
LayoutTests/fast/hidpi/resources/image?test.png [new file with mode: 0644]
LayoutTests/fast/loader/image-src-question-mark-expected.txt [new file with mode: 0644]
LayoutTests/fast/loader/image-src-question-mark.html [new file with mode: 0644]
LayoutTests/fast/loader/resources/image?test.png [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLParserIdioms.cpp

index 35283f2a17060be9669a41ac29dd918f258844c0..6644fb31e37bd414bfcd7b6131c3ea645a0e6705 100644 (file)
@@ -1,3 +1,20 @@
+2013-09-19  Yoav Weiss  <yoav@yoav.ws>
+
+        Remove URL decoding in srcset handling
+        https://bugs.webkit.org/show_bug.cgi?id=121609
+
+        Reviewed by Benjamin Poulain.
+
+        These tests make sure that encoded URLs are properly handled, and especially URLs 
+        with a question mark in them.
+        
+        * fast/hidpi/image-srcset-question-mark-expected.txt: Added.
+        * fast/hidpi/image-srcset-question-mark.html: Added.
+        * fast/hidpi/resources/image?test.png: Added.
+        * fast/loader/image-src-question-mark-expected.txt: Added.
+        * fast/loader/image-src-question-mark.html: Added.
+        * fast/loader/resources/image?test.png: Added.
+
 2013-09-19  Grzegorz Czajkowski  <g.czajkowski@samsung.com>
 
         Use shouldBecomeEqual in asynchronous spellchecking tests.
diff --git a/LayoutTests/fast/hidpi/image-srcset-question-mark-expected.txt b/LayoutTests/fast/hidpi/image-srcset-question-mark-expected.txt
new file mode 100644 (file)
index 0000000..b09af52
--- /dev/null
@@ -0,0 +1,3 @@
+PASS document.getElementById("foo").clientWidth==25 is true
+This test passes if the image below is displayed.
+
diff --git a/LayoutTests/fast/hidpi/image-srcset-question-mark.html b/LayoutTests/fast/hidpi/image-srcset-question-mark.html
new file mode 100644 (file)
index 0000000..8c86753
--- /dev/null
@@ -0,0 +1,19 @@
+<html>
+    <head>
+        <script src="../../resources/js-test-pre.js"></script>
+        <script>
+             if (window.testRunner) {
+                 testRunner.dumpAsText();
+             }
+
+             addEventListener("load", function() {
+                 shouldBeTrue('document.getElementById("foo").clientWidth==25');
+             }, false);
+        </script>
+    </head>
+
+    <body id="body">
+        <div>This test passes if the image below is displayed.</div>
+        <img id="foo" srcset="resources/image%3Ftest.png">
+    </body>
+</html>
diff --git a/LayoutTests/fast/hidpi/resources/image?test.png b/LayoutTests/fast/hidpi/resources/image?test.png
new file mode 100644 (file)
index 0000000..6e555e3
Binary files /dev/null and b/LayoutTests/fast/hidpi/resources/image?test.png differ
diff --git a/LayoutTests/fast/loader/image-src-question-mark-expected.txt b/LayoutTests/fast/loader/image-src-question-mark-expected.txt
new file mode 100644 (file)
index 0000000..b09af52
--- /dev/null
@@ -0,0 +1,3 @@
+PASS document.getElementById("foo").clientWidth==25 is true
+This test passes if the image below is displayed.
+
diff --git a/LayoutTests/fast/loader/image-src-question-mark.html b/LayoutTests/fast/loader/image-src-question-mark.html
new file mode 100644 (file)
index 0000000..82f9912
--- /dev/null
@@ -0,0 +1,19 @@
+<html>
+    <head>
+        <script src="../../resources/js-test-pre.js"></script>
+        <script>
+             if (window.testRunner) {
+                 testRunner.dumpAsText();
+             }
+
+             addEventListener("load", function() {
+                 shouldBeTrue('document.getElementById("foo").clientWidth==25');
+             }, false);
+        </script>
+    </head>
+
+    <body id="body">
+        <div>This test passes if the image below is displayed.</div>
+        <img id="foo" src="resources/image%3Ftest.png">
+    </body>
+</html>
diff --git a/LayoutTests/fast/loader/resources/image?test.png b/LayoutTests/fast/loader/resources/image?test.png
new file mode 100644 (file)
index 0000000..6e555e3
Binary files /dev/null and b/LayoutTests/fast/loader/resources/image?test.png differ
index b3b665b8d2d34c22250ea316daf1438a5fd91c49..72679ad020017544e9c8f189359eeee484f945f9 100644 (file)
@@ -1,3 +1,19 @@
+2013-09-19  Yoav Weiss  <yoav@yoav.ws>
+
+        Remove URL decoding in srcset handling
+        https://bugs.webkit.org/show_bug.cgi?id=121609
+
+        Reviewed by Benjamin Poulain.
+
+        Tests: fast/hidpi/image-srcset-question-mark.html
+               fast/loader/image-src-question-mark.html
+
+        Removed URL decoding from src and srcset's handling algorithm, since they break encoded URLS.
+
+        * html/parser/HTMLParserIdioms.cpp:
+        (WebCore::parseImagesWithScaleFromSrcSetAttribute):
+        (WebCore::bestFitSourceForImageAttributes):
+
 2013-09-19  Anders Carlsson  <andersca@apple.com>
 
         Avoid calling AtomicString::lower() in makeFontGlyphsCacheKey
index ed57dbb8f22b190d822f64811f5abbb8df3e838d..76dc2615b18f86b1fb7256d01d3ac25d88e2a954 100644 (file)
@@ -388,7 +388,7 @@ static void parseImagesWithScaleFromSrcSetAttribute(const String& srcSetAttribut
             }
         }
         ImageWithScale image;
-        image.imageURL = decodeURLEscapeSequences(StringImpl::createWithoutCopying(srcSetAttribute.characters() + imageUrlStart, imageUrlEnd - imageUrlStart));
+        image.imageURL = StringImpl::createWithoutCopying(srcSetAttribute.characters() + imageUrlStart, imageUrlEnd - imageUrlStart);
         image.scaleFactor = imgScaleFactor;
 
         imageCandidates.append(image);
@@ -406,7 +406,7 @@ String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& sr
     const String src =  srcAttribute.simplifyWhiteSpace(isHTMLSpace);
     if (!src.isEmpty()) {
         ImageWithScale image;
-        image.imageURL = decodeURLEscapeSequences(src);
+        image.imageURL = src;
         image.scaleFactor = 1.0;
 
         imageCandidates.append(image);
@@ -419,9 +419,9 @@ String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& sr
 
     for (size_t i = 0; i < imageCandidates.size() - 1; ++i) {
         if (imageCandidates[i].scaleFactor >= deviceScaleFactor)
-            return imageCandidates[i].imageURL;
+            return String(imageCandidates[i].imageURL);
     }
-    return imageCandidates.last().imageURL;
+    return String(imageCandidates.last().imageURL);
 }
 
 }