Changeset 204952 in webkit


Ignore:
Timestamp:
Aug 24, 2016 7:40:55 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Implement CSS.escape as per CSSOM
https://bugs.webkit.org/show_bug.cgi?id=126337

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2016-08-24
Reviewed by Dean Jackson.

Source/WebCore:

Test: css3/escape-dom-api.html

  • css/CSSOMUtils.cpp:

(WebCore::serializeIdentifier):
Update serialization to match the latest version of the spec:
<https://drafts.csswg.org/cssom/#serialize-an-identifier>
New handling for 0x0, 0x7f, just "-", and "--" is now allowed.

  • css/DOMCSSNamespace.cpp:

(WebCore::DOMCSSNamespace::escape):

  • css/DOMCSSNamespace.h:
  • css/DOMCSSNamespace.idl:

New CSS.escape method.

LayoutTests:

CSS.escape is part of the CSSOM Spec:
https://drafts.csswg.org/cssom/#the-css.escape%28%29-method

Tests:
https://github.com/mathiasbynens/CSS.escape/blob/master/tests/tests.js

Change is based on the Blink change (patch by <rob.buis@samsung.com>) and follow-ups:
<https://chromium.googlesource.com/chromium/blink/+/c1a5ffdc924b089e70cd33ad2726b58cc8312abe>

  • css3/escape-dom-api-expected.txt: Added.
  • css3/escape-dom-api.html: Added.

New tests, taken from the polyfill.

  • fast/css/parsing-css-nonascii-expected.txt:
  • fast/css/parsing-css-nonascii.html:
  • fast/css/selector-text-escape.html:

Update existing tests now that 0x7f is escaped.

  • js/dom/function-removed-after-parsing-expected.txt:
  • js/dom/function-removed-after-parsing.html:

Rename use of CSS.escape here now that CSS.escape exists.

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r204951 r204952  
     12016-08-24  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Implement `CSS.escape` as per CSSOM
     4        https://bugs.webkit.org/show_bug.cgi?id=126337
     5
     6        Reviewed by Dean Jackson.
     7
     8        CSS.escape is part of the CSSOM Spec:
     9        https://drafts.csswg.org/cssom/#the-css.escape%28%29-method
     10
     11        Tests:
     12        https://github.com/mathiasbynens/CSS.escape/blob/master/tests/tests.js
     13
     14        Change is based on the Blink change (patch by <rob.buis@samsung.com>) and follow-ups:
     15        <https://chromium.googlesource.com/chromium/blink/+/c1a5ffdc924b089e70cd33ad2726b58cc8312abe>
     16
     17        * css3/escape-dom-api-expected.txt: Added.
     18        * css3/escape-dom-api.html: Added.
     19        New tests, taken from the polyfill.
     20
     21        * fast/css/parsing-css-nonascii-expected.txt:
     22        * fast/css/parsing-css-nonascii.html:
     23        * fast/css/selector-text-escape.html:
     24        Update existing tests now that 0x7f is escaped.
     25
     26        * js/dom/function-removed-after-parsing-expected.txt:
     27        * js/dom/function-removed-after-parsing.html:
     28        Rename use of `CSS.escape` here now that `CSS.escape` exists.
     29
    1302016-08-24  Zalan Bujtas  <zalan@apple.com>
    231
  • trunk/LayoutTests/fast/css/parsing-css-nonascii-expected.txt

    r98744 r204952  
    55Rules from the stylesheet:
    66
    7 #a127_\ { color: red; }
     7#a127_\7f { color: red; }
    88#a128_€ { color: red; }
    99#b128_€ { color: green; }
     
    1616Expected result:
    1717
    18 #a127_\ { color: red; }
     18#a127_\7f { color: red; }
    1919#a128_€ { color: red; }
    2020#b128_€ { color: green; }
  • trunk/LayoutTests/fast/css/parsing-css-nonascii.html

    r120683 r204952  
    66  === Warning ===
    77
    8   This file intentionally contains scpecial characters which
     8  This file intentionally contains special characters which
    99  cannot be displayed by some text editors. Please
    1010  carefully edit the file.
     
    6565<p>Expected result:</p>
    6666
    67 <pre id="expected">#a127_\ { color: red; }
     67<pre id="expected">#a127_\7f { color: red; }
    6868#a128_€ { color: red; }
    6969#b128_€ { color: green; }
  • trunk/LayoutTests/fast/css/selector-text-escape.html

    r155263 r204952  
    9494    ".-\\30 _class",
    9595    ".-\\39 _class",
    96     ".-\\-_class",
     96    ".--_class",
    9797    ".\x81_class",
    9898    ".日本語_class",
  • trunk/LayoutTests/js/dom/function-removed-after-parsing-expected.txt

    r200518 r204952  
    1 window.CSS.escape still here
     1window.CSS.layoutTestEscape still here
    22
  • trunk/LayoutTests/js/dom/function-removed-after-parsing.html

    r200518 r204952  
    33NOTE: This intentionally does not use description() and does not include js-test-post because
    44doing either of those things made the bug go away.
     5
     6NOTE: This intentionally does not use the name `CSS.escape` because that function exists now but
     7did not when this test was added. The name was changed to `CSS.layoutTestEscape` for this test.
    58-->
    69  <script src="../../resources/js-test-pre.js"></script>
     
    2124        InvalidCharacterError.prototype.name = 'InvalidCharacterError';
    2225
    23         if (!CSS.escape) {
     26        if (!CSS.layoutTestEscape) {
    2427                // https://drafts.csswg.org/cssom/#serialize-an-identifier
    25                 CSS.escape = function(value) {
     28                CSS.layoutTestEscape = function(value) {
    2629                        var string = String(value);
    2730                        var length = string.length;
     
    113116      testRunner.waitUntilDone();
    114117    } catch (e) { }
    115     if (!window.CSS.escape) {
    116       debug('window.CSS.escape not loaded');
     118    if (!window.CSS.layoutTestEscape) {
     119      debug('window.CSS.layoutTestEscape not loaded');
    117120    }
    118121    setTimeout(function() {
    119       if (window.CSS.escape)
    120         debug("window.CSS.escape still here");
     122      if (window.CSS.layoutTestEscape)
     123        debug("window.CSS.layoutTestEscape still here");
    121124      else
    122         debug('window.CSS.escape missing in event');
     125        debug('window.CSS.layoutTestEscape missing in event');
    123126      try {
    124127        testRunner.notifyDone();
  • trunk/Source/WebCore/ChangeLog

    r204951 r204952  
     12016-08-24  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Implement `CSS.escape` as per CSSOM
     4        https://bugs.webkit.org/show_bug.cgi?id=126337
     5
     6        Reviewed by Dean Jackson.
     7
     8        Test: css3/escape-dom-api.html
     9
     10        * css/CSSOMUtils.cpp:
     11        (WebCore::serializeIdentifier):
     12        Update serialization to match the latest version of the spec:
     13        <https://drafts.csswg.org/cssom/#serialize-an-identifier>
     14        New handling for 0x0, 0x7f, just "-", and "--" is now allowed.
     15
     16        * css/DOMCSSNamespace.cpp:
     17        (WebCore::DOMCSSNamespace::escape):
     18        * css/DOMCSSNamespace.h:
     19        * css/DOMCSSNamespace.idl:
     20        New CSS.escape method.
     21
    1222016-08-24  Zalan Bujtas  <zalan@apple.com>
    223
  • trunk/Source/WebCore/css/CSSOMUtils.cpp

    r166044 r204952  
    5858    while (index < identifier.length()) {
    5959        UChar32 c = identifier.characterStartingAt(index);
     60        if (!c) {
     61            // Check for lone surrogate which characterStartingAt does not return.
     62            c = identifier[index];
     63        }
     64
    6065        index += U16_LENGTH(c);
    6166
    62         if (c <= 0x1f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isFirstCharHyphen))))
     67        if (!c)
     68            appendTo.append(0xfffd);
     69        else if (c <= 0x1f || c == 0x7f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isFirstCharHyphen))))
    6370            serializeCharacterAsCodePoint(c, appendTo);
    64         else if (c == 0x2d && isSecond && isFirstCharHyphen)
     71        else if (c == 0x2d && isFirst && index == identifier.length())
    6572            serializeCharacter(c, appendTo);
    6673        else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
     
    7380            isSecond = true;
    7481            isFirstCharHyphen = (c == 0x2d);
    75         } else if (isSecond) {
     82        } else if (isSecond)
    7683            isSecond = false;
    77         }
    7884    }
    7985}
  • trunk/Source/WebCore/css/DOMCSSNamespace.cpp

    r201290 r204952  
    3131#include "DOMCSSNamespace.h"
    3232
     33#include "CSSOMUtils.h"
    3334#include "CSSParser.h"
    3435#include "StyleProperties.h"
     36#include <wtf/text/StringBuilder.h>
    3537#include <wtf/text/WTFString.h>
    3638
     
    7880}
    7981
     82String DOMCSSNamespace::escape(const String& ident)
     83{
     84    StringBuilder builder;
     85    serializeIdentifier(ident, builder);
     86    return builder.toString();
    8087}
     88
     89}
  • trunk/Source/WebCore/css/DOMCSSNamespace.h

    r199112 r204952  
    3939    static bool supports(const String& property, const String& value);
    4040    static bool supports(const String& conditionText);
     41    static String escape(const String& ident);
    4142};
    4243
  • trunk/Source/WebCore/css/DOMCSSNamespace.idl

    r199112 r204952  
    3434    static boolean supports(DOMString property, DOMString value);
    3535    static boolean supports(DOMString conditionText);
     36    static DOMString escape(DOMString ident);
    3637};
Note: See TracChangeset for help on using the changeset viewer.