Changeset 32879 in webkit


Ignore:
Timestamp:
May 5, 2008 11:29:09 AM (16 years ago)
Author:
ap@webkit.org
Message:

Reviewed by Darin.

https://bugs.webkit.org/show_bug.cgi?id=11947
nbsps should be converted to entities in innerHTML

https://bugs.webkit.org/show_bug.cgi?id=18769
replacing   with spaces using regexp creates inconsistent result

Tests: fast/dom/innerHTML-nbsp.html

fast/dom/innerHTML-escaping-attribute.html

  • editing/markup.cpp: (WebCore::appendAttributeValue): (WebCore::escapeContentText): (WebCore::appendEscapedContent): Added U+00a0/nbsp to the list of characters to escape.
Location:
trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r32878 r32879  
     12008-05-05  Alexey Proskuryakov  <ap@webkit.org>
     2
     3        Reviewed by Darin.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=11947
     6        nbsps should be converted to entities in innerHTML
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=18769
     9        replacing &nbsp; with spaces using regexp creates inconsistent result
     10
     11        * fast/dom/innerHTML-nbsp-expected.txt: Added.
     12        * fast/dom/innerHTML-nbsp.html: Added.
     13        * fast/dom/innerHTML-escaping-attribute-expected.txt: Added.
     14        * fast/dom/innerHTML-escaping-attribute.html: Added.
     15
     16        * editing/inserting/edited-whitespace-1.html: Updated expected results.
     17
    1182008-05-05  David Hyatt  <hyatt@apple.com>
    219
  • trunk/WebCore/ChangeLog

    r32878 r32879  
     12008-05-05  Alexey Proskuryakov  <ap@webkit.org>
     2
     3        Reviewed by Darin.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=11947
     6        nbsps should be converted to entities in innerHTML
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=18769
     9        replacing &nbsp; with spaces using regexp creates inconsistent result
     10
     11        Tests: fast/dom/innerHTML-nbsp.html
     12               fast/dom/innerHTML-escaping-attribute.html
     13
     14        * editing/markup.cpp:
     15        (WebCore::appendAttributeValue):
     16        (WebCore::escapeContentText):
     17        (WebCore::appendEscapedContent):
     18        Added U+00a0/nbsp to the list of characters to escape.
     19
    1202008-05-05  David Hyatt  <hyatt@apple.com>
    221
  • trunk/WebCore/editing/markup.cpp

    r32531 r32879  
    2828
    2929#include "CDATASection.h"
     30#include "CharacterNames.h"
     31#include "Comment.h"
    3032#include "CSSComputedStyleDeclaration.h"
    3133#include "CSSPrimitiveValue.h"
     
    3840#include "CSSValue.h"
    3941#include "CSSValueKeywords.h"
    40 #include "Comment.h"
    4142#include "DeleteButtonController.h"
    4243#include "Document.h"
     
    9798    static const String ltEntity("&lt;");
    9899    static const String quotEntity("&quot;");
     100    static const String nbspEntity("&nbsp;");
    99101   
    100102    for (unsigned i = 0; i < len; ++i) {
     
    115117                append(result, quotEntity);
    116118                lastCopiedFrom = i + 1;
     119                break;
     120            case noBreakSpace:
     121                result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
     122                append(result, nbspEntity);
     123                lastCopiedFrom = i + 1;
     124                break;
    117125        }
    118126    }
     
    121129}
    122130
    123 static void append(Vector<UChar>& vector, const char* string)
    124 {
    125     const char* p = string;
    126     while (*p) {
    127         UChar c = *p++;
    128         vector.append(c);
    129     }
    130 }
    131    
    132131static String escapeContentText(const String& in)
    133132{
     
    137136    unsigned lastCopiedFrom = 0;
    138137
     138    static const String ampEntity("&amp;");
     139    static const String ltEntity("&lt;");
     140    static const String nbspEntity("&nbsp;");
     141
    139142    s.reserveCapacity(len);
    140143
     
    143146    for (unsigned i = 0; i < len; ++i) {
    144147        UChar c = characters[i];
    145         if ((c == '&') | (c == '<')) {
    146             s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
    147             if (c == '&')
    148                 append(s, "&amp;");
    149             else
    150                 append(s, "&lt;");
    151             lastCopiedFrom = i + 1;
     148        switch (c) {
     149            case '&':
     150                s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
     151                append(s, ampEntity);
     152                lastCopiedFrom = i + 1;
     153                break;
     154            case '<':
     155                s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
     156                append(s, ltEntity);
     157                lastCopiedFrom = i + 1;
     158                break;
     159            case noBreakSpace:
     160                s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
     161                append(s, nbspEntity);
     162                lastCopiedFrom = i + 1;
     163                break;
    152164        }
    153165    }
     
    166178    static const String ampEntity("&amp;");
    167179    static const String ltEntity("&lt;");
    168    
     180    static const String nbspEntity("&nbsp;");
     181
    169182    for (unsigned i = 0; i < len; ++i) {
    170183        UChar c = uchars[i];
    171         if ((c == '&') | (c == '<')) {
    172             result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
    173             if (c == '&')
     184        switch (c) {
     185            case '&':
     186                result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
    174187                append(result, ampEntity);
    175             else
     188                lastCopiedFrom = i + 1;
     189                break;
     190            case '<':
     191                result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
    176192                append(result, ltEntity);
    177             lastCopiedFrom = i + 1;
     193                lastCopiedFrom = i + 1;
     194                break;
     195            case noBreakSpace:
     196                result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
     197                append(result, nbspEntity);
     198                lastCopiedFrom = i + 1;
     199                break;
    178200        }
    179201    }
Note: See TracChangeset for help on using the changeset viewer.