Changeset 94213 in webkit


Ignore:
Timestamp:
Aug 31, 2011 12:01:08 PM (13 years ago)
Author:
Nate Chapin
Message:

Source/WebCore: Don't load resources with empty urls, since this
will resolve to the current document.
https://bugs.webkit.org/show_bug.cgi?id=30303

Reviewed by Darin Adler.

Test: http/tests/loading/empty-urls.html

  • dom/ScriptElement.cpp:

(WebCore::ScriptElement::requestScript): If src="", fail through

to the error event case.

  • html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::parseMappedAttribute): Ensure the url

stays empty if we try to resolve an empty href.

  • loader/ImageLoader.cpp:

(WebCore::ImageLoader::updateFromElement): Throw an error instead of

loading if the src is empty in all cases, not just local files.

LayoutTests: Test updates for https://bugs.webkit.org/show_bug.cgi?id=30303.

Reviewed by Darin Adler.

  • fast/images/load-img-with-empty-src-expected.txt:
  • fast/images/load-img-with-empty-src.html: Expect the same behavior whether or not an empty src

is in a local file document.

  • fast/tokenizer/002-expected.txt: Added.
  • fast/tokenizer/002.html: Make dumpAsText().
  • fast/tokenizer/external-script-document-write_2-expected.txt: Added.
  • fast/tokenizer/external-script-document-write_2.html:: Make dumpAsText().
  • fast/tokenizer/script_extra_close-expected.txt: Added.
  • fast/tokenizer/script_extra_close.html:: Make dumpAsText().
  • http/tests/loading/empty-urls-expected.txt: Added.
  • http/tests/loading/empty-urls.html: Added. Test empty urls with a bunch of subresource types

and ensure their error event behavior matches the spec.

  • platform/chromium-cg-mac/fast/tokenizer/002-expected.txt: Removed.
  • platform/chromium-cg-mac/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
  • platform/chromium-linux/fast/tokenizer/002-expected.png: Removed.
  • platform/chromium-linux/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
  • platform/chromium-linux/fast/tokenizer/script_extra_close-expected.png: Removed.
  • platform/chromium-win/fast/tokenizer/002-expected.png: Removed.
  • platform/chromium-win/fast/tokenizer/002-expected.txt: Removed.
  • platform/chromium-win/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
  • platform/chromium-win/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
  • platform/chromium-win/fast/tokenizer/script_extra_close-expected.png: Removed.
  • platform/chromium-win/fast/tokenizer/script_extra_close-expected.txt: Removed.
  • platform/gtk/fast/tokenizer/002-expected.png: Removed.
  • platform/gtk/fast/tokenizer/002-expected.txt: Removed.
  • platform/gtk/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
  • platform/gtk/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
  • platform/gtk/fast/tokenizer/script_extra_close-expected.png: Removed.
  • platform/gtk/fast/tokenizer/script_extra_close-expected.txt: Removed.
  • platform/mac-leopard/fast/tokenizer/002-expected.png: Removed.
  • platform/mac-leopard/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
  • platform/mac-leopard/fast/tokenizer/script_extra_close-expected.png: Removed.
  • platform/mac/fast/tokenizer/002-expected.png: Removed.
  • platform/mac/fast/tokenizer/002-expected.txt: Removed.
  • platform/mac/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
  • platform/mac/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
  • platform/mac/fast/tokenizer/script_extra_close-expected.png: Removed.
  • platform/mac/fast/tokenizer/script_extra_close-expected.txt: Removed.
  • platform/qt/fast/tokenizer/002-expected.png: Removed.
  • platform/qt/fast/tokenizer/002-expected.txt: Removed.
  • platform/qt/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
  • platform/qt/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
  • platform/qt/fast/tokenizer/script_extra_close-expected.png: Removed.
  • platform/qt/fast/tokenizer/script_extra_close-expected.txt: Removed.
Location:
trunk
Files:
5 added
32 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r94212 r94213  
     12011-08-31  Nate Chapin  <japhet@chromium.org>
     2
     3        Test updates for https://bugs.webkit.org/show_bug.cgi?id=30303.
     4
     5        Reviewed by Darin Adler.
     6
     7        * fast/images/load-img-with-empty-src-expected.txt:
     8        * fast/images/load-img-with-empty-src.html: Expect the same behavior whether or not an empty src
     9            is in a local file document.
     10        * fast/tokenizer/002-expected.txt: Added.
     11        * fast/tokenizer/002.html: Make dumpAsText().
     12        * fast/tokenizer/external-script-document-write_2-expected.txt: Added.
     13        * fast/tokenizer/external-script-document-write_2.html:: Make dumpAsText().
     14        * fast/tokenizer/script_extra_close-expected.txt: Added.
     15        * fast/tokenizer/script_extra_close.html:: Make dumpAsText().
     16        * http/tests/loading/empty-urls-expected.txt: Added.
     17        * http/tests/loading/empty-urls.html: Added. Test empty urls with a bunch of subresource types
     18            and ensure their error event behavior matches the spec.
     19        * platform/chromium-cg-mac/fast/tokenizer/002-expected.txt: Removed.
     20        * platform/chromium-cg-mac/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
     21        * platform/chromium-linux/fast/tokenizer/002-expected.png: Removed.
     22        * platform/chromium-linux/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
     23        * platform/chromium-linux/fast/tokenizer/script_extra_close-expected.png: Removed.
     24        * platform/chromium-win/fast/tokenizer/002-expected.png: Removed.
     25        * platform/chromium-win/fast/tokenizer/002-expected.txt: Removed.
     26        * platform/chromium-win/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
     27        * platform/chromium-win/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
     28        * platform/chromium-win/fast/tokenizer/script_extra_close-expected.png: Removed.
     29        * platform/chromium-win/fast/tokenizer/script_extra_close-expected.txt: Removed.
     30        * platform/gtk/fast/tokenizer/002-expected.png: Removed.
     31        * platform/gtk/fast/tokenizer/002-expected.txt: Removed.
     32        * platform/gtk/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
     33        * platform/gtk/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
     34        * platform/gtk/fast/tokenizer/script_extra_close-expected.png: Removed.
     35        * platform/gtk/fast/tokenizer/script_extra_close-expected.txt: Removed.
     36        * platform/mac-leopard/fast/tokenizer/002-expected.png: Removed.
     37        * platform/mac-leopard/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
     38        * platform/mac-leopard/fast/tokenizer/script_extra_close-expected.png: Removed.
     39        * platform/mac/fast/tokenizer/002-expected.png: Removed.
     40        * platform/mac/fast/tokenizer/002-expected.txt: Removed.
     41        * platform/mac/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
     42        * platform/mac/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
     43        * platform/mac/fast/tokenizer/script_extra_close-expected.png: Removed.
     44        * platform/mac/fast/tokenizer/script_extra_close-expected.txt: Removed.
     45        * platform/qt/fast/tokenizer/002-expected.png: Removed.
     46        * platform/qt/fast/tokenizer/002-expected.txt: Removed.
     47        * platform/qt/fast/tokenizer/external-script-document-write_2-expected.png: Removed.
     48        * platform/qt/fast/tokenizer/external-script-document-write_2-expected.txt: Removed.
     49        * platform/qt/fast/tokenizer/script_extra_close-expected.png: Removed.
     50        * platform/qt/fast/tokenizer/script_extra_close-expected.txt: Removed.
     51
    1522011-08-31  Simon Fraser  <simon.fraser@apple.com>
    253
  • trunk/LayoutTests/fast/images/load-img-with-empty-src-expected.txt

    r34853 r94213  
    77[2] define a <img> with src='' to see whether it gets loaded. (It should NOT be loaded, because the base URI is a local file.)
    88PASS
    9 [3] change the base URI to an http: URL and define a <img> with src='' to see whether it gets loaded. (It should be loaded.)
     9[3] change the base URI to an http: URL and define a <img> with src='' to see whether it gets loaded. (It should NOT be loaded.)
    1010PASS
  • trunk/LayoutTests/fast/images/load-img-with-empty-src.html

    r34853 r94213  
    1515        }
    1616       
    17         var results = [true, true, true, false];
     17        var results = [true, true, false, false];
    1818        var description = ["remove src attribute of an <img> to see whether it gets loaded. (It should NOT be loaded.)",
    1919                           "define an <img> with no src specified to see whether it gets loaded. (It should NOT be loaded.)",
    2020                           "define a <img> with src='' to see whether it gets loaded. (It should NOT be loaded, because the base URI is a local file.)",
    21                            "change the base URI to an http: URL and define a <img> with src='' to see whether it gets loaded. (It should be loaded.)" ]
     21                           "change the base URI to an http: URL and define a <img> with src='' to see whether it gets loaded. (It should NOT be loaded.)" ]
    2222
    2323        function outputResults() {
     
    3838    <img id="image1" style="display:none" src="resources/test-load.jpg" onerror="results[0] = false;" />
    3939    <img id="image2" style="display:none" onerror="results[1] = false;" />
    40     <img id="image3" style="display:none" src="" onerror="results[2] = false;" />
     40    <img id="image3" style="display:none" src="" onerror="results[2] = true;" />
    4141    <script type="text/javascript">
    4242        var imgNode1 = document.getElementById("image1");
  • trunk/LayoutTests/fast/tokenizer/002.html

    r11995 r94213  
    11<script>
     2if (window.layoutTestController)
     3    layoutTestController.dumpAsText();
    24document.write("<script src>");
    35document.writeln("</scr" + "ipt>");
  • trunk/LayoutTests/fast/tokenizer/external-script-document-write_2.html

    r11995 r94213  
    11<html>
     2<script>
     3if (window.layoutTestController)
     4    layoutTestController.dumpAsText();
     5</script>
    26<body>
    37<script>
  • trunk/LayoutTests/fast/tokenizer/script_extra_close.html

    r11995 r94213  
    11<html>
     2<script>
     3if (window.layoutTestController)
     4    layoutTestController.dumpAsText();
     5</script>
    26<body>
    37TEST...                                         
  • trunk/Source/WebCore/ChangeLog

    r94211 r94213  
     12011-08-31  Nate Chapin  <japhet@chromium.org>
     2
     3        Don't load resources with empty urls, since this
     4        will resolve to the current document.
     5        https://bugs.webkit.org/show_bug.cgi?id=30303
     6
     7        Reviewed by Darin Adler.
     8
     9        Test: http/tests/loading/empty-urls.html
     10
     11        * dom/ScriptElement.cpp:
     12        (WebCore::ScriptElement::requestScript): If src="", fail through
     13            to the error event case.
     14        * html/HTMLLinkElement.cpp:
     15        (WebCore::HTMLLinkElement::parseMappedAttribute): Ensure the url
     16            stays empty if we try to resolve an empty href.
     17        * loader/ImageLoader.cpp:
     18        (WebCore::ImageLoader::updateFromElement): Throw an error instead of
     19            loading if the src is empty in all cases, not just local files.
     20
    1212011-08-28  Robert Hogan  <robert@webkit.org>
    222
  • trunk/Source/WebCore/dom/ScriptElement.cpp

    r93871 r94213  
    3333#include "FrameLoader.h"
    3434#include "HTMLNames.h"
     35#include "HTMLParserIdioms.h"
    3536#include "HTMLScriptElement.h"
    3637#include "IgnoreDestructiveWriteCountIncrementer.h"
     
    255256
    256257    ASSERT(!m_cachedScript);
    257     // FIXME: If sourceUrl is empty, we should dispatchErrorEvent().
    258     ResourceRequest request(m_element->document()->completeURL(sourceUrl));
    259     m_cachedScript = m_element->document()->cachedResourceLoader()->requestScript(request, scriptCharset());
    260     m_isExternalScript = true;
     258    if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
     259        ResourceRequest request(m_element->document()->completeURL(sourceUrl));
     260        m_cachedScript = m_element->document()->cachedResourceLoader()->requestScript(request, scriptCharset());
     261        m_isExternalScript = true;
     262    }
    261263
    262264    if (m_cachedScript) {
  • trunk/Source/WebCore/html/HTMLLinkElement.cpp

    r93439 r94213  
    134134        process();
    135135    } else if (attr->name() == hrefAttr) {
    136         m_url = document()->completeURL(stripLeadingAndTrailingHTMLSpaces(attr->value()));
     136        String url = stripLeadingAndTrailingHTMLSpaces(attr->value());
     137        m_url = url.isEmpty() ? KURL() : document()->completeURL(url);
    137138        process();
    138139    } else if (attr->name() == typeAttr) {
  • trunk/Source/WebCore/loader/ImageLoader.cpp

    r93886 r94213  
    2828#include "Document.h"
    2929#include "Element.h"
     30#include "Event.h"
    3031#include "HTMLNames.h"
    3132#include "HTMLObjectElement.h"
     33#include "HTMLParserIdioms.h"
    3234#include "RenderImage.h"
    3335
     
    160162
    161163    // Do not load any image if the 'src' attribute is missing or if it is
    162     // an empty string referring to a local file. The latter condition is
    163     // a quirk that preserves old behavior that Dashboard widgets
    164     // need (<rdar://problem/5994621>).
     164    // an empty string.
    165165    CachedImage* newImage = 0;
    166     if (!(attr.isNull() || (attr.isEmpty() && document->baseURI().isLocalFile()))) {
     166    if (!attr.isNull() && !stripLeadingAndTrailingHTMLSpaces(attr).isEmpty()) {
    167167        ResourceRequest request = ResourceRequest(document->completeURL(sourceURI(attr)));
    168168
     
    187187        // violation occurred.
    188188        m_failedLoadURL = !newImage ? attr : AtomicString();
    189     }
     189    } else if (!attr.isNull()) // Fire an error event if the url is empty.
     190        m_element->dispatchEvent(Event::create(eventNames().errorEvent, false, false));
    190191   
    191192    CachedImage* oldImage = m_image.get();
Note: See TracChangeset for help on using the changeset viewer.