Made SetTitle call ReduceEntities for bug #1398

This commit is contained in:
kipp%netscape.com 1998-11-17 16:29:25 +00:00
Родитель a87dd1063b
Коммит 2098c2a448
2 изменённых файлов: 84 добавлений и 72 удалений

Просмотреть файл

@ -272,33 +272,9 @@ public:
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Temporary factory code to create content objects
static void static void
GetAttributeValueAt(const nsIParserNode& aNode, ReduceEntities(nsString& aString)
PRInt32 aIndex,
nsString& aResult,
nsIScriptContextOwner* aScriptContextOwner)
{ {
// Copy value
const nsString& value = aNode.GetValueAt(aIndex);
aResult.Truncate();
aResult.Append(value);
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
// Reduce any entities // Reduce any entities
// XXX Note: as coded today, this will only convert well formed // XXX Note: as coded today, this will only convert well formed
// entities. This may not be compatible enough. // entities. This may not be compatible enough.
@ -307,21 +283,21 @@ GetAttributeValueAt(const nsIParserNode& aNode,
// so we should add a translate numeric entity method from the parser... // so we should add a translate numeric entity method from the parser...
char cbuf[100]; char cbuf[100];
PRInt32 index = 0; PRInt32 index = 0;
while (index < aResult.Length()) { while (index < aString.Length()) {
// If we have the start of an entity (and it's not at the end of // If we have the start of an entity (and it's not at the end of
// our string) then translate the entity into it's unicode value. // our string) then translate the entity into it's unicode value.
if ((aResult.CharAt(index++) == '&') && (index < aResult.Length())) { if ((aString.CharAt(index++) == '&') && (index < aString.Length())) {
PRInt32 start = index - 1; PRInt32 start = index - 1;
PRUnichar e = aResult.CharAt(index); PRUnichar e = aString.CharAt(index);
if (e == '#') { if (e == '#') {
// Convert a numeric character reference // Convert a numeric character reference
index++; index++;
char* cp = cbuf; char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1; char* limit = cp + sizeof(cbuf) - 1;
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length(); PRInt32 slen = aString.Length();
while ((index < slen) && (cp < limit)) { while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index); PRUnichar e = aString.CharAt(index);
if (e == ';') { if (e == ';') {
index++; index++;
ok = PR_TRUE; ok = PR_TRUE;
@ -348,8 +324,8 @@ GetAttributeValueAt(const nsIParserNode& aNode,
// Remove entity from string and replace it with the integer // Remove entity from string and replace it with the integer
// value. // value.
aResult.Cut(start, index - start); aString.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start); aString.Insert(PRUnichar(ch), start);
index = start + 1; index = start + 1;
} }
else if (((e >= 'A') && (e <= 'Z')) || else if (((e >= 'A') && (e <= 'Z')) ||
@ -360,9 +336,9 @@ GetAttributeValueAt(const nsIParserNode& aNode,
char* limit = cp + sizeof(cbuf) - 1; char* limit = cp + sizeof(cbuf) - 1;
*cp++ = char(e); *cp++ = char(e);
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length(); PRInt32 slen = aString.Length();
while ((index < slen) && (cp < limit)) { while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index); PRUnichar e = aString.CharAt(index);
if (e == ';') { if (e == ';') {
index++; index++;
ok = PR_TRUE; ok = PR_TRUE;
@ -388,8 +364,8 @@ GetAttributeValueAt(const nsIParserNode& aNode,
// Remove entity from string and replace it with the integer // Remove entity from string and replace it with the integer
// value. // value.
aResult.Cut(start, index - start); aString.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start); aString.Insert(PRUnichar(ch), start);
index = start + 1; index = start + 1;
} }
else if (e == '{') { else if (e == '{') {
@ -400,6 +376,35 @@ GetAttributeValueAt(const nsIParserNode& aNode,
} }
} }
// Temporary factory code to create content objects
static void
GetAttributeValueAt(const nsIParserNode& aNode,
PRInt32 aIndex,
nsString& aResult,
nsIScriptContextOwner* aScriptContextOwner)
{
// Copy value
const nsString& value = aNode.GetValueAt(aIndex);
aResult.Truncate();
aResult.Append(value);
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
ReduceEntities(aResult);
}
static PRBool static PRBool
FindAttribute(const nsIParserNode& aNode, FindAttribute(const nsIParserNode& aNode,
const nsString& aKeyName, const nsString& aKeyName,
@ -1454,6 +1459,7 @@ HTMLContentSink::SetTitle(const nsString& aValue)
else { else {
*mTitle = aValue; *mTitle = aValue;
} }
ReduceEntities(*mTitle);
mTitle->CompressWhitespace(PR_TRUE, PR_TRUE); mTitle->CompressWhitespace(PR_TRUE, PR_TRUE);
((nsHTMLDocument*)mDocument)->SetTitle(*mTitle); ((nsHTMLDocument*)mDocument)->SetTitle(*mTitle);

Просмотреть файл

@ -272,33 +272,9 @@ public:
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Temporary factory code to create content objects
static void static void
GetAttributeValueAt(const nsIParserNode& aNode, ReduceEntities(nsString& aString)
PRInt32 aIndex,
nsString& aResult,
nsIScriptContextOwner* aScriptContextOwner)
{ {
// Copy value
const nsString& value = aNode.GetValueAt(aIndex);
aResult.Truncate();
aResult.Append(value);
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
// Reduce any entities // Reduce any entities
// XXX Note: as coded today, this will only convert well formed // XXX Note: as coded today, this will only convert well formed
// entities. This may not be compatible enough. // entities. This may not be compatible enough.
@ -307,21 +283,21 @@ GetAttributeValueAt(const nsIParserNode& aNode,
// so we should add a translate numeric entity method from the parser... // so we should add a translate numeric entity method from the parser...
char cbuf[100]; char cbuf[100];
PRInt32 index = 0; PRInt32 index = 0;
while (index < aResult.Length()) { while (index < aString.Length()) {
// If we have the start of an entity (and it's not at the end of // If we have the start of an entity (and it's not at the end of
// our string) then translate the entity into it's unicode value. // our string) then translate the entity into it's unicode value.
if ((aResult.CharAt(index++) == '&') && (index < aResult.Length())) { if ((aString.CharAt(index++) == '&') && (index < aString.Length())) {
PRInt32 start = index - 1; PRInt32 start = index - 1;
PRUnichar e = aResult.CharAt(index); PRUnichar e = aString.CharAt(index);
if (e == '#') { if (e == '#') {
// Convert a numeric character reference // Convert a numeric character reference
index++; index++;
char* cp = cbuf; char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1; char* limit = cp + sizeof(cbuf) - 1;
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length(); PRInt32 slen = aString.Length();
while ((index < slen) && (cp < limit)) { while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index); PRUnichar e = aString.CharAt(index);
if (e == ';') { if (e == ';') {
index++; index++;
ok = PR_TRUE; ok = PR_TRUE;
@ -348,8 +324,8 @@ GetAttributeValueAt(const nsIParserNode& aNode,
// Remove entity from string and replace it with the integer // Remove entity from string and replace it with the integer
// value. // value.
aResult.Cut(start, index - start); aString.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start); aString.Insert(PRUnichar(ch), start);
index = start + 1; index = start + 1;
} }
else if (((e >= 'A') && (e <= 'Z')) || else if (((e >= 'A') && (e <= 'Z')) ||
@ -360,9 +336,9 @@ GetAttributeValueAt(const nsIParserNode& aNode,
char* limit = cp + sizeof(cbuf) - 1; char* limit = cp + sizeof(cbuf) - 1;
*cp++ = char(e); *cp++ = char(e);
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length(); PRInt32 slen = aString.Length();
while ((index < slen) && (cp < limit)) { while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index); PRUnichar e = aString.CharAt(index);
if (e == ';') { if (e == ';') {
index++; index++;
ok = PR_TRUE; ok = PR_TRUE;
@ -388,8 +364,8 @@ GetAttributeValueAt(const nsIParserNode& aNode,
// Remove entity from string and replace it with the integer // Remove entity from string and replace it with the integer
// value. // value.
aResult.Cut(start, index - start); aString.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start); aString.Insert(PRUnichar(ch), start);
index = start + 1; index = start + 1;
} }
else if (e == '{') { else if (e == '{') {
@ -400,6 +376,35 @@ GetAttributeValueAt(const nsIParserNode& aNode,
} }
} }
// Temporary factory code to create content objects
static void
GetAttributeValueAt(const nsIParserNode& aNode,
PRInt32 aIndex,
nsString& aResult,
nsIScriptContextOwner* aScriptContextOwner)
{
// Copy value
const nsString& value = aNode.GetValueAt(aIndex);
aResult.Truncate();
aResult.Append(value);
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
ReduceEntities(aResult);
}
static PRBool static PRBool
FindAttribute(const nsIParserNode& aNode, FindAttribute(const nsIParserNode& aNode,
const nsString& aKeyName, const nsString& aKeyName,
@ -1454,6 +1459,7 @@ HTMLContentSink::SetTitle(const nsString& aValue)
else { else {
*mTitle = aValue; *mTitle = aValue;
} }
ReduceEntities(*mTitle);
mTitle->CompressWhitespace(PR_TRUE, PR_TRUE); mTitle->CompressWhitespace(PR_TRUE, PR_TRUE);
((nsHTMLDocument*)mDocument)->SetTitle(*mTitle); ((nsHTMLDocument*)mDocument)->SetTitle(*mTitle);