Commit 095e1f6b authored by ap@webkit.org's avatar ap@webkit.org

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.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@32879 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3cb88e1a
2008-05-05 Alexey Proskuryakov <ap@webkit.org>
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 &nbsp; with spaces using regexp creates inconsistent result
* fast/dom/innerHTML-nbsp-expected.txt: Added.
* fast/dom/innerHTML-nbsp.html: Added.
* fast/dom/innerHTML-escaping-attribute-expected.txt: Added.
* fast/dom/innerHTML-escaping-attribute.html: Added.
* editing/inserting/edited-whitespace-1.html: Updated expected results.
2008-05-05 David Hyatt <hyatt@apple.com>
Fix for https://bugs.webkit.org/show_bug.cgi?id=18821, putImageData incorrect when data has alpha.
<html>
<head>
<meta charset="utf-8">
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
</script>
<script>
function getContent() {
var regx=new RegExp('&nbsp;','gi');
if (document.body.innerHTML.search("&nbsp;&nbsp;'&quot;") < 0)
document.write("FAIL: <xmp>" + document.body.innerHTML + "</xmp>");
else
document.write("PASS<p>");
}
</script>
</head>
<body onload="getContent()"><div id="div" foo="&nbsp; '&quot;"></div></body></html>
<html>
<head>
<meta charset="utf-8">
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
</script>
<script>
function getContent() {
var regx=new RegExp('&nbsp;','gi');
var a=document.body.innerHTML.replace(regx,' ');
var h='';
for(var i=0;i<a.length;i++) {
if (a.charCodeAt(i) != 32 && a.charCodeAt(i) != 0x0a) {
document.write("RegExp FAIL<p>");
return;
}
}
if (document.body.innerHTML.search("&nbsp;&nbsp;&nbsp;&nbsp;") < 0) {
document.write("innerHTML FAIL: <xmp>" + document.body.innerHTML + "</xmp>");
return;
}
document.write("PASS<p>");
}
</script>
</head>
<body onload="getContent()">&nbsp;&nbsp;  </body></html>
2008-05-05 Alexey Proskuryakov <ap@webkit.org>
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 &nbsp; 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.
2008-05-05 David Hyatt <hyatt@apple.com>
Fix for https://bugs.webkit.org/show_bug.cgi?id=18821. Fix some bugs in both get/PutImageData of <canvas>.
......@@ -27,6 +27,8 @@
#include "markup.h"
#include "CDATASection.h"
#include "CharacterNames.h"
#include "Comment.h"
#include "CSSComputedStyleDeclaration.h"
#include "CSSPrimitiveValue.h"
#include "CSSProperty.h"
......@@ -37,7 +39,6 @@
#include "CSSStyleSelector.h"
#include "CSSValue.h"
#include "CSSValueKeywords.h"
#include "Comment.h"
#include "DeleteButtonController.h"
#include "Document.h"
#include "DocumentFragment.h"
......@@ -96,6 +97,7 @@ static void appendAttributeValue(Vector<UChar>& result, const String& attr)
static const String ampEntity("&amp;");
static const String ltEntity("&lt;");
static const String quotEntity("&quot;");
static const String nbspEntity("&nbsp;");
for (unsigned i = 0; i < len; ++i) {
UChar c = uchars[i];
......@@ -114,21 +116,18 @@ static void appendAttributeValue(Vector<UChar>& result, const String& attr)
result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
append(result, quotEntity);
lastCopiedFrom = i + 1;
break;
case noBreakSpace:
result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
append(result, nbspEntity);
lastCopiedFrom = i + 1;
break;
}
}
result.append(uchars + lastCopiedFrom, len - lastCopiedFrom);
}
static void append(Vector<UChar>& vector, const char* string)
{
const char* p = string;
while (*p) {
UChar c = *p++;
vector.append(c);
}
}
static String escapeContentText(const String& in)
{
Vector<UChar> s;
......@@ -136,19 +135,32 @@ static String escapeContentText(const String& in)
unsigned len = in.length();
unsigned lastCopiedFrom = 0;
static const String ampEntity("&amp;");
static const String ltEntity("&lt;");
static const String nbspEntity("&nbsp;");
s.reserveCapacity(len);
const UChar* characters = in.characters();
for (unsigned i = 0; i < len; ++i) {
UChar c = characters[i];
if ((c == '&') | (c == '<')) {
s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
if (c == '&')
append(s, "&amp;");
else
append(s, "&lt;");
lastCopiedFrom = i + 1;
switch (c) {
case '&':
s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
append(s, ampEntity);
lastCopiedFrom = i + 1;
break;
case '<':
s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
append(s, ltEntity);
lastCopiedFrom = i + 1;
break;
case noBreakSpace:
s.append(characters + lastCopiedFrom, i - lastCopiedFrom);
append(s, nbspEntity);
lastCopiedFrom = i + 1;
break;
}
}
......@@ -165,16 +177,26 @@ static void appendEscapedContent(Vector<UChar>& result, pair<const UChar*, size_
static const String ampEntity("&amp;");
static const String ltEntity("&lt;");
static const String nbspEntity("&nbsp;");
for (unsigned i = 0; i < len; ++i) {
UChar c = uchars[i];
if ((c == '&') | (c == '<')) {
result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
if (c == '&')
switch (c) {
case '&':
result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
append(result, ampEntity);
else
lastCopiedFrom = i + 1;
break;
case '<':
result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
append(result, ltEntity);
lastCopiedFrom = i + 1;
lastCopiedFrom = i + 1;
break;
case noBreakSpace:
result.append(uchars + lastCopiedFrom, i - lastCopiedFrom);
append(result, nbspEntity);
lastCopiedFrom = i + 1;
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment