Fixes a bug in the view source parsing of text within <script>,
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2008 03:20:44 +0000 (03:20 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2008 03:20:44 +0000 (03:20 +0000)
<style>, <xmp>, <textarea> and other special tags. The text was
being parsed as HTML and would be syntax highlighted if a "<"
was encountered.

<rdar://problem/5790805> Inspector's source view missing some words,
doubles others in JS source in <script> tag (17752)

Reviewed by Dave Hyatt.

Added test: fast/frames/viewsource-plain-text-tags.html

* html/HTMLTokenizer.cpp:
(WebCore::HTMLTokenizer::scriptHandler): Set scriptCodeSize and
scriptCodeResync to zero before an early return in view source mode.
This was causing text from a previous script tag to show up in
then next style tag.
(WebCore::HTMLTokenizer::parseTag): Enter an if block in view source
mode even if n is null. The n is property guarded in other places
and not used by view source mode. Removes a redundant null check on n.
Add a new null check of n before setting scriptSrcCharset. Other code
in HTMLTokenizer is already guarded for this code path.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@33509 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/frames/resources/viewsource-frame-2.html [new file with mode: 0644]
LayoutTests/fast/frames/viewsource-plain-text-tags-expected.txt [new file with mode: 0644]
LayoutTests/fast/frames/viewsource-plain-text-tags.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLTokenizer.cpp

index 2694913..86b090d 100644 (file)
@@ -1,3 +1,14 @@
+2008-05-15  Timothy Hatcher  <timothy@apple.com>
+
+        Test case added for <rdar://problem/5790805> Inspector's source view
+        missing some words, doubles others in JS source in <script> tag (17752)
+
+        Reviewed by Dave Hyatt.
+
+        * fast/frames/resources/viewsource-frame-2.html: Added.
+        * fast/frames/viewsource-plain-text-tags-expected.txt: Added.
+        * fast/frames/viewsource-plain-text-tags.html: Added.
+
 2008-05-15  Stephanie Lewis  <slewis@apple.com>
 
         Reviewed by Anders.
diff --git a/LayoutTests/fast/frames/resources/viewsource-frame-2.html b/LayoutTests/fast/frames/resources/viewsource-frame-2.html
new file mode 100644 (file)
index 0000000..ff4bed1
--- /dev/null
@@ -0,0 +1,15 @@
+<script>
+<test>
+</script>
+
+<style>
+<test>
+</style>
+
+<xmp>
+<test>
+</xmp>
+
+<textarea>
+<test>
+</textarea>
diff --git a/LayoutTests/fast/frames/viewsource-plain-text-tags-expected.txt b/LayoutTests/fast/frames/viewsource-plain-text-tags-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/frames/viewsource-plain-text-tags.html b/LayoutTests/fast/frames/viewsource-plain-text-tags.html
new file mode 100644 (file)
index 0000000..3dd32d0
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+<head>
+<script>
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+
+    function report(frame) {
+        var result = frame.contentDocument.documentElement.innerHTML;
+        var regex = new RegExp("<td class=\"webkit-line-content\">&lt;test&gt;</td>", "g");
+        matches = result.match(regex);
+
+        if (matches && matches.length === 4)
+            var resultText = "PASS";
+        else
+            var resultText = "FAIL";
+
+        if (window.layoutTestController) {
+            document.open();
+            document.write(resultText);
+            document.close();
+
+            layoutTestController.notifyDone();
+        } else {
+            document.getElementById("result").textContent = resultText;
+        }
+    }
+</script>
+</head>
+<body>
+<p>You should see a frame in 'view source' mode below.</p>
+<p>None of the "&lt;test&gt;" strings shown below should be colorized like HTML.</p>
+<hr>
+<iframe viewsource src="resources/viewsource-frame-2.html" height="250" onload="report(this)"></iframe>
+<hr>
+<div id="result"></div>
+</body>
+</html>
index cfbf8cf..046f580 100644 (file)
@@ -1,5 +1,30 @@
 2008-05-15  Timothy Hatcher  <timothy@apple.com>
 
+        Fixes a bug in the view source parsing of text within <script>,
+        <style>, <xmp>, <textarea> and other special tags. The text was
+        being parsed as HTML and would be syntax highlighted if a "<"
+        was encountered.
+
+        <rdar://problem/5790805> Inspector's source view missing some words,
+        doubles others in JS source in <script> tag (17752)
+
+        Reviewed by Dave Hyatt.
+
+        Added test: fast/frames/viewsource-plain-text-tags.html
+
+        * html/HTMLTokenizer.cpp:
+        (WebCore::HTMLTokenizer::scriptHandler): Set scriptCodeSize and
+        scriptCodeResync to zero before an early return in view source mode.
+        This was causing text from a previous script tag to show up in
+        then next style tag.
+        (WebCore::HTMLTokenizer::parseTag): Enter an if block in view source
+        mode even if n is null. The n is property guarded in other places
+        and not used by view source mode. Removes a redundant null check on n.
+        Add a new null check of n before setting scriptSrcCharset. Other code
+        in HTMLTokenizer is already guarded for this code path. 
+
+2008-05-15  Timothy Hatcher  <timothy@apple.com>
+
         Changes the Web Inspector node highlight to be less aggressive
         and only highlight when hovering over the selected node in the DOM
         tree or breadcrumbs. You can highlight on hover for any node if
index 4beeed1..b4e3534 100644 (file)
@@ -442,6 +442,7 @@ HTMLTokenizer::State HTMLTokenizer::scriptHandler(State state)
     processToken();
 
     state.setInScript(false);
+    scriptCodeSize = scriptCodeResync = 0;
     
     // FIXME: The script should be syntax highlighted.
     if (inViewSourceMode())
@@ -450,7 +451,6 @@ HTMLTokenizer::State HTMLTokenizer::scriptHandler(State state)
     SegmentedString *savedPrependingSrc = currentPrependingSrc;
     SegmentedString prependingSrc;
     currentPrependingSrc = &prependingSrc;
-    scriptCodeSize = scriptCodeResync = 0;
 
     if (!parser->skipMode() && !followingFrameset) {
         if (cs) {
@@ -1478,14 +1478,15 @@ HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString &src, State state)
 
             RefPtr<Node> n = processToken();
             m_cBufferPos = cBufferPos;
-            if (n) {
+            if (n || inViewSourceMode()) {
                 if ((tagName == preTag || tagName == listingTag) && !inViewSourceMode()) {
                     if (beginTag)
                         state.setDiscardLF(true); // Discard the first LF after we open a pre.
-                } else if (tagName == scriptTag && n) {
+                } else if (tagName == scriptTag) {
                     ASSERT(!scriptNode);
                     scriptNode = n;
-                    scriptSrcCharset = static_cast<HTMLScriptElement*>(n.get())->scriptCharset();
+                    if (n)
+                        scriptSrcCharset = static_cast<HTMLScriptElement*>(n.get())->scriptCharset();
                     if (beginTag) {
                         searchStopper = scriptEnd;
                         searchStopperLen = 8;