[Webkit-unassigned] [Bug 106593] New: StylePropertySet::asText() incorrectly serializes some styles.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jan 10 12:03:44 PST 2013


https://bugs.webkit.org/show_bug.cgi?id=106593

           Summary: StylePropertySet::asText() incorrectly serializes some
                    styles.
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Unspecified
        OS/Version: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: CSS
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: bmcquade at google.com
                CC: apavlov at chromium.org, alexis at webkit.org


StylePropertySet::asText() incorrectly serializes some styles. This causes e.g. document.styleSheets[n].cssRules[m].cssText to generate the wrong CSS text in some cases. I've attached an HTML file which demonstrates one such case.

StylePropertySet::asText() is quite complex. It's trying to do clever things with background-position and background-repeat that I do not believe are necessary.

Here is a simpler implementation which correctly reserializes a CSSStyleDeclaration. This could be used in PropertySetCSSStyleDeclaration::cssText() in place of the current call to StylePropertySet::asText().

WTF::String SerializeCSSStyleDeclaration(WebCore::CSSStyleDeclaration* decl) {
  WTF::StringBuilder style_text;
  WTF::HashSet<WTF::String> emitted_properties;
  for (int i = 0; i < decl->length(); ++i) {
    WTF::String name = decl->item(i);
    if (name.isEmpty()) {
      continue;
    }

    // Now see if this property was part of a shorthand declaration,
    // e.g. background-image might have been part of a background
    // shorthand propertly declaration. If there is a shorthand, then
    // we emit the shorthand property instead if it hasn't already
    // been emitted.
    const WTF::String shorthand = decl->getPropertyShorthand(name);
    if (!shorthand.isEmpty()) {
      name = shorthand;
    }
    if (emitted_properties.contains(name)) {
      // If we encounter two properties that share the same shorthand,
      // we only want to emit that shorthand once.
      continue;
    }

    emitted_properties.add(name);
    const WTF::String value = decl->getPropertyValue(name);
    if (value.isEmpty()) {
      continue;
    }

    if (!style_text.isEmpty()) {
      style_text.append(';');
    }
    style_text.append(name);
    style_text.append(':');
    style_text.append(value);
    const WTF::String priority = decl->getPropertyPriority(name);
    if (!priority.isEmpty()) {
      style_text.append(" !");
      style_text.append(priority);
    }
  }
  return style_text.toString();
}

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list