Changeset 88110 in webkit


Ignore:
Timestamp:
Jun 4, 2011, 4:23:09 AM (14 years ago)
Author:
ap@apple.com
Message:

2011-06-04 Alexey Proskuryakov <ap@apple.com>

Reviewed by Darin Adler.

Input value sanitization for text fields is incorrect
https://bugs.webkit.org/show_bug.cgi?id=62061
<rdar://problem/9553273>

  • fast/forms/input-value-sanitization-expected.txt:
  • fast/forms/input-value-sanitization.html:
  • fast/forms/paste-multiline-text-input.html:
  • fast/forms/script-tests/input-value-sanitization.js: Removed.

2011-06-04 Alexey Proskuryakov <ap@apple.com>

Reviewed by Darin Adler.

Input value sanitization for text fields is incorrect
https://bugs.webkit.org/show_bug.cgi?id=62061
<rdar://problem/9553273>

Newline characters should be removed according to HTML5, not replaced with spaces.
This also matches Safari 5 behavior.

  • html/TextFieldInputType.cpp: (WebCore::isASCIILineBreak): A functor for removeCharacters(). (WebCore::limitLength): Do one thing at once. (WebCore::TextFieldInputType::sanitizeValue): Sanitization removes newlines. (WebCore::TextFieldInputType::handleBeforeTextInsertedEvent): Moved (somewhat surprising) code that replaces newlines with spaces here.
Location:
trunk
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r88104 r88110  
     12011-06-04  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Input value sanitization for text fields is incorrect
     6        https://bugs.webkit.org/show_bug.cgi?id=62061
     7        <rdar://problem/9553273>
     8
     9        * fast/forms/input-value-sanitization-expected.txt:
     10        * fast/forms/input-value-sanitization.html:
     11        * fast/forms/paste-multiline-text-input.html:
     12        * fast/forms/script-tests/input-value-sanitization.js: Removed.
     13
    1142011-06-04  Jeffrey Pfau  <jpfau@apple.com>
    215
  • trunk/LayoutTests/fast/forms/input-value-sanitization-expected.txt

    r82801 r88110  
    11Tests for value sanitization algorithm.
    2 
    3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    4 
    52
    63
     
    1411
    1512Text:
    16 PASS input.value is "   foo bar  "
    17 PASS document.getSelection().toString() is "   foo bar  "
     13PASS input.value is " foo bar "
     14PASS document.getSelection().toString() is " foo bar "
    1815PASS successfullyParsed is true
    1916
  • trunk/LayoutTests/fast/forms/input-value-sanitization.html

    r63876 r88110  
    66</head>
    77<body>
    8 <p id="description"></p>
     8<p>Tests for value sanitization algorithm.</p>
    99<div id="console"></div>
    10 <script src="script-tests/input-value-sanitization.js"></script>
     10<script>
     11var input;
     12
     13debug('');
     14debug('Number:');
     15input = document.createElement('input');
     16input.setAttribute('value', '65536');
     17input.type = 'number';
     18shouldBe('input.value', '"65536"');
     19shouldBe('input.value = "256"; input.value', '"256"');
     20shouldBe('input.value = ""; input.value', '""');
     21
     22
     23debug('');
     24debug('Range:');
     25input = document.createElement('input');
     26input.type = 'text';
     27input.value = ':)';
     28input.type = 'range';
     29shouldBe('input.value', '"50"');
     30
     31debug('');
     32debug('Text:');
     33var container = document.createElement('div');
     34document.body.appendChild(container);
     35container.innerHTML = '<input type="text" id="text" value="\n\r foo bar \n\r\n">';
     36input = document.getElementById('text');
     37shouldBe('input.value', '" foo bar "');
     38input.focus();
     39document.execCommand('SelectAll');
     40shouldBe('document.getSelection().toString()', '" foo bar "');
     41
     42// FIXME: Add more sanitization tests.
     43// https://bugs.webkit.org/show_bug.cgi?id=37024
     44
     45container.innerHTML = '';
     46var successfullyParsed = true;
     47
     48</script>
    1149<script src="../../fast/js/resources/js-test-post.js"></script>
    1250</body>
  • trunk/LayoutTests/fast/forms/paste-multiline-text-input.html

    r37539 r88110  
    1111
    1212        var DEFAULT_LINE_1 = "line\t(1 of 2)\r\nline\t(2 of 2)";
    13         var EXPECTED_LINE_1 = "line\t(1 of 2) line\t(2 of 2)";
     13        var EXPECTED_LINE_1 = "line\t(1 of 2)line\t(2 of 2)";
    1414
     15        // FIXME: Is this really expected behavior to truncate the string at a null byte?
     16        // It doesn't match Firefox 4 and common sense.
    1517        var DEFAULT_LINE_2 = "null\0char";
    1618        var EXPECTED_LINE_2 = "null";
  • trunk/Source/WebCore/ChangeLog

    r88104 r88110  
     12011-06-04  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        Input value sanitization for text fields is incorrect
     6        https://bugs.webkit.org/show_bug.cgi?id=62061
     7        <rdar://problem/9553273>
     8
     9        Newline characters should be removed according to HTML5, not replaced with spaces.
     10        This also matches Safari 5 behavior.
     11
     12        * html/TextFieldInputType.cpp:
     13        (WebCore::isASCIILineBreak): A functor for removeCharacters().
     14        (WebCore::limitLength): Do one thing at once.
     15        (WebCore::TextFieldInputType::sanitizeValue): Sanitization removes newlines.
     16        (WebCore::TextFieldInputType::handleBeforeTextInsertedEvent): Moved (somewhat surprising)
     17        code that replaces newlines with spaces here.
     18
    1192011-06-04  Jeffrey Pfau  <jpfau@apple.com>
    220
  • trunk/Source/WebCore/html/TextFieldInputType.cpp

    r87980 r88110  
    209209}
    210210
    211 static String replaceEOLAndLimitLength(const String& proposedValue, int maxLength)
    212 {
    213     String string = proposedValue;
    214     string.replace("\r\n", " ");
    215     string.replace('\r', ' ');
    216     string.replace('\n', ' ');
    217 
     211static bool isASCIILineBreak(UChar c)
     212{
     213    return c == '\r' || c == '\n';
     214}
     215
     216static String limitLength(const String& string, int maxLength)
     217{
    218218    unsigned newLength = numCharactersInGraphemeClusters(string, maxLength);
    219219    for (unsigned i = 0; i < newLength; ++i) {
     
    236236    }
    237237#endif
    238     return replaceEOLAndLimitLength(proposedValue, HTMLInputElement::maximumLength);
     238    return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInputElement::maximumLength);
    239239}
    240240
     
    274274    }
    275275#endif
    276     event->setText(replaceEOLAndLimitLength(event->text(), appendableLength));
     276
     277    String eventText = event->text();
     278    eventText.replace("\r\n", " ");
     279    eventText.replace('\r', ' ');
     280    eventText.replace('\n', ' ');
     281
     282    event->setText(limitLength(eventText, appendableLength));
    277283}
    278284
Note: See TracChangeset for help on using the changeset viewer.