Bug 742414 & Bug 731234 - Highlight script end tag correctly in View Source and avoid crashing when doing so. r=smaug.

This commit is contained in:
Henri Sivonen 2012-04-17 14:53:52 +03:00
parent cc07746d4f
commit 891bce48d7
9 changed files with 74 additions and 9 deletions

View File

@ -163,9 +163,7 @@ nsHtml5Highlighter::Transition(PRInt32 aState, bool aReconsume, PRInt32 aPos)
StartSpan();
mAmpersand = CurrentNode();
} else {
EndCharacters();
StartSpan();
mCurrentRun = CurrentNode();
EndCharactersAndStartMarkupRun();
}
break;
case NS_HTML5TOKENIZER_TAG_OPEN:
@ -413,6 +411,8 @@ nsHtml5Highlighter::Transition(PRInt32 aState, bool aReconsume, PRInt32 aPos)
case NS_HTML5TOKENIZER_SCRIPT_DATA_LESS_THAN_SIGN:
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:
if (aState == NS_HTML5TOKENIZER_NON_DATA_END_TAG_NAME) {
FlushCurrent();
StartSpan(); // don't know if it is "end-tag" yet :-(
break;
}
FinishTag();
@ -421,8 +421,7 @@ nsHtml5Highlighter::Transition(PRInt32 aState, bool aReconsume, PRInt32 aPos)
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED:
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH:
if (aState == NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN) {
EndCharacters();
StartSpan();
EndCharactersAndStartMarkupRun();
}
break;
// Lots of double escape states omitted, because they don't highlight.
@ -555,12 +554,15 @@ nsHtml5Highlighter::StartCharacters()
}
void
nsHtml5Highlighter::EndCharacters()
nsHtml5Highlighter::EndCharactersAndStartMarkupRun()
{
NS_PRECONDITION(mInCharacters, "Not in characters!");
FlushChars();
Pop();
mInCharacters = false;
// Now start markup run
StartSpan();
mCurrentRun = CurrentNode();
}
void

View File

@ -204,7 +204,7 @@ class nsHtml5Highlighter
/**
* Ends a wrapper around a run of characters.
*/
void EndCharacters();
void EndCharactersAndStartMarkupRun();
/**
* Starts an <a>.

View File

@ -0,0 +1,4 @@
<script></script
><script></script
><script></script
>

View File

@ -50,3 +50,4 @@ load 650501-1.xhtml
load 696651-1.html
load view-source:699347-1.xml
load 721313-1.html
load view-source:742414-1.html

View File

@ -7,7 +7,7 @@
<span id></span>&lt;!--
<span id></span>var s = "&lt;script&gt;foo&lt;/script&gt;";
<span id></span>--&gt;
<span id></span><span class="end-tag">&lt;/script&gt;</span><span></span><span class="comment">&lt;!-- Not quite optimal highlight there. --&gt;</span>
<span id></span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span></span><span class="comment">&lt;!-- Comment. --&gt;</span>
<span id></span><span>&lt;<span class="start-tag">style</span>&gt;</span>
<span id></span>/* &lt;/foo&gt; */
<span id></span><span>&lt;/<span class="end-tag">style</span>&gt;</span>

View File

@ -7,7 +7,7 @@ var lt = "<";
<!--
var s = "<script>foo</script>";
-->
</script><!-- Not quite optimal highlight there. -->
</script><!-- Comment. -->
<style>
/* </foo> */
</style>

View File

@ -0,0 +1,30 @@
<!DOCTYPE html><html><head><title></title><link rel="stylesheet" type="text/css" href="resource://gre-resources/viewsource.css"></head><body id="viewsource" class="wrap"><pre id><span class="doctype">&lt;!DOCTYPE html&gt;</span><span>
<span id></span></span><span>&lt;<span class="start-tag">body</span>&gt;</span><span>
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span> &gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;/<span class="end-tag">script</span>
<span id></span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span title="End tag had attributes." class="error">&lt;/<span class="end-tag">script</span> <span class="attribute-name">foo</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span title="End tag had attributes." class="error">&lt;/<span class="end-tag">script</span> <span class="attribute-name">foo</span>=<a class="attribute-value">bar</a>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span title="End tag had attributes." class="error">&lt;/<span class="end-tag">script</span> <span class="attribute-name">foo</span>="<a class="attribute-value">bar</a>"&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- </span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- </span><span>&lt;/<span class="end-tag">script</span> &gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- </span><span>&lt;/<span class="end-tag">script</span>
<span id></span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- </span><span title="End tag had attributes." class="error">&lt;/<span class="end-tag">script</span> <span class="attribute-name">foo</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- </span><span title="End tag had attributes." class="error">&lt;/<span class="end-tag">script</span> <span class="attribute-name">foo</span>=<a class="attribute-value">bar</a>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- </span><span title="End tag had attributes." class="error">&lt;/<span class="end-tag">script</span> <span class="attribute-name">foo</span>="<a class="attribute-value">bar</a>"&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- -</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- --</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>-- --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript&gt; &lt;/script&gt; </span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript&gt; &lt;/script&gt; --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript &lt;/script&gt; --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript&gt; &lt;/script &gt; --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript&gt; &lt;/script foo&gt; --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript&gt; &lt;/script foo=bar&gt; --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span><span>&lt;<span class="start-tag">script</span>&gt;</span><span></span><span>&lt;!</span><span>--</span><span>&lt;s</span><span>cript&gt; &lt;/script foo="bar"&gt; --&gt;</span><span>&lt;/<span class="end-tag">script</span>&gt;</span><span>X
<span id></span></span>
</pre>
<!-- View source CSS matches the <pre id> and <span id> elements and produces line numbers. -->

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<body>
<script></script>X
<script></script >X
<script></script
>X
<script></script foo>X
<script></script foo=bar>X
<script></script foo="bar">X
<script><!--</script>X
<script><!-- </script>X
<script><!-- </script >X
<script><!-- </script
>X
<script><!-- </script foo>X
<script><!-- </script foo=bar>X
<script><!-- </script foo="bar">X
<script><!-- -</script>X
<script><!-- --</script>X
<script><!-- --></script>X
<script><!--<script> </script> </script>X
<script><!--<script> </script> --></script>X
<script><!--<script </script> --></script>X
<script><!--<script> </script > --></script>X
<script><!--<script> </script foo> --></script>X
<script><!--<script> </script foo=bar> --></script>X
<script><!--<script> </script foo="bar"> --></script>X

View File

@ -19,3 +19,4 @@ fails-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated) == vi
== bug696651-2.html bug696651-2-ref.html
== view-source:bug700260-1.html view-source:bug700260-1-ref.html
== view-source:bug704667-1.html bug704667-1-ref.html
== view-source:bug731234-1.html bug731234-1-ref.html