Changed to ignore SCRIPT tags that aren't JavaScript language

This commit is contained in:
troy%netscape.com 1998-10-30 03:36:35 +00:00
Родитель 42bb7d7f21
Коммит f9c8d7ff13
2 изменённых файлов: 230 добавлений и 144 удалений

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

@ -2112,13 +2112,41 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode)
#define SCRIPT_BUF_SIZE 1024
// Returns PR_TRUE if the language name is a version of JavaScript and
// PR_FALSE otherwise
static PRBool
IsJavaScriptLanguage(const nsString& aName)
{
if (aName.EqualsIgnoreCase("JavaScript") ||
aName.EqualsIgnoreCase("LiveScript") ||
aName.EqualsIgnoreCase("Mocha")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
return PR_TRUE;
}
else {
return PR_FALSE;
}
}
nsresult
HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
{
nsresult rv = NS_OK;
PRBool isJavaScript = PR_TRUE;
PRInt32 i, ac = aNode.GetAttributeCount();
// Look for SRC attribute
// Look for SRC attribute and look for a LANGUAGE attribute
nsAutoString src;
for (i = 0; i < ac; i++) {
const nsString& key = aNode.GetKeyAt(i);
@ -2126,8 +2154,22 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
src = aNode.GetValueAt(i);
src.Trim("\"", PR_TRUE, PR_TRUE);
}
else if (key.EqualsIgnoreCase("type")) {
nsAutoString type;
GetAttributeValueAt(aNode, i, type, nsnull);
isJavaScript = type.EqualsIgnoreCase("text/javascript");
}
else if (key.EqualsIgnoreCase("language")) {
nsAutoString lang;
GetAttributeValueAt(aNode, i, lang, nsnull);
isJavaScript = IsJavaScriptLanguage(lang);
}
}
// Don't process scripts that aren't JavaScript
if (isJavaScript) {
nsAutoString script;
// If there is a SRC attribute, (for now) read from the
@ -2205,6 +2247,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
NS_RELEASE(owner);
}
}
}
return rv;
}

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

@ -2112,13 +2112,41 @@ HTMLContentSink::ProcessMETATag(const nsIParserNode& aNode)
#define SCRIPT_BUF_SIZE 1024
// Returns PR_TRUE if the language name is a version of JavaScript and
// PR_FALSE otherwise
static PRBool
IsJavaScriptLanguage(const nsString& aName)
{
if (aName.EqualsIgnoreCase("JavaScript") ||
aName.EqualsIgnoreCase("LiveScript") ||
aName.EqualsIgnoreCase("Mocha")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
return PR_TRUE;
}
else {
return PR_FALSE;
}
}
nsresult
HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
{
nsresult rv = NS_OK;
PRBool isJavaScript = PR_TRUE;
PRInt32 i, ac = aNode.GetAttributeCount();
// Look for SRC attribute
// Look for SRC attribute and look for a LANGUAGE attribute
nsAutoString src;
for (i = 0; i < ac; i++) {
const nsString& key = aNode.GetKeyAt(i);
@ -2126,8 +2154,22 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
src = aNode.GetValueAt(i);
src.Trim("\"", PR_TRUE, PR_TRUE);
}
else if (key.EqualsIgnoreCase("type")) {
nsAutoString type;
GetAttributeValueAt(aNode, i, type, nsnull);
isJavaScript = type.EqualsIgnoreCase("text/javascript");
}
else if (key.EqualsIgnoreCase("language")) {
nsAutoString lang;
GetAttributeValueAt(aNode, i, lang, nsnull);
isJavaScript = IsJavaScriptLanguage(lang);
}
}
// Don't process scripts that aren't JavaScript
if (isJavaScript) {
nsAutoString script;
// If there is a SRC attribute, (for now) read from the
@ -2205,6 +2247,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
NS_RELEASE(owner);
}
}
}
return rv;
}