Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 780908 - Fix crash in editor when head after body. r=ehsan, a=Sta…

…ndard8 for checkin to Thunderbird specific relbranch CLOSED TREE

--HG--
branch : COMM1501_2012090708_RELBRANCH
extra : transplant_source : %C8%92Rq5%CDl%ED%5B%E7%5E%FB%3E%E1G%40W%F6m%91
  • Loading branch information...
commit 35587831f1919d78d2c46f0422be4d00f7c7fe9f 1 parent cf366b2
R Kent James authored September 01, 2012
9  editor/libeditor/html/nsHTMLEditor.cpp
@@ -1500,6 +1500,9 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString)
1500 1500
   aSourceString.EndReading(endhead);
1501 1501
   bool foundhead = CaseInsensitiveFindInReadable(NS_LITERAL_STRING("<head"),
1502 1502
                                                    beginhead, endhead);
  1503
+  // a valid head appears before the body
  1504
+  if (foundbody && beginhead.get() > beginbody.get())
  1505
+    foundhead = false;
1503 1506
 
1504 1507
   nsReadingIterator<PRUnichar> beginclosehead;
1505 1508
   nsReadingIterator<PRUnichar> endclosehead;
@@ -1509,6 +1512,12 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString)
1509 1512
   // Find the index after "<head>"
1510 1513
   bool foundclosehead = CaseInsensitiveFindInReadable(
1511 1514
            NS_LITERAL_STRING("</head>"), beginclosehead, endclosehead);
  1515
+  // a valid close head appears after a found head
  1516
+  if (foundhead && beginhead.get() > beginclosehead.get())
  1517
+    foundclosehead = false;
  1518
+  // a valid close head appears before a found body
  1519
+  if (foundbody && beginclosehead.get() > beginbody.get())
  1520
+    foundclosehead = false;
1512 1521
   
1513 1522
   // Time to change the document
1514 1523
   nsAutoEditBatch beginBatching(this);
1  editor/libeditor/html/tests/Makefile.in
@@ -103,6 +103,7 @@ _CHROME_TEST_FILES = \
103 103
 		test_bug607584.xul \
104 104
 		test_bug616590.xul \
105 105
 		test_bug635636.html \
  106
+		test_bug780908.xul \
106 107
 		green.png \
107 108
 		$(NULL)
108 109
 
113  editor/libeditor/html/tests/test_bug780908.xul
... ...
@@ -0,0 +1,113 @@
  1
+<?xml version="1.0"?>
  2
+<?xml-stylesheet href="chrome://global/skin"
  3
+                 type="text/css"?>
  4
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
  5
+                 type="text/css"?>
  6
+<!--
  7
+https://bugzilla.mozilla.org/show_bug.cgi?id=780908
  8
+
  9
+adapted from test_bug607584.xul by Kent James <kent@caspia.com>
  10
+-->
  11
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  12
+        title="Mozilla Bug 780908" onload="runTest();">
  13
+  <script type="application/javascript"
  14
+    src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
  15
+  <script type="application/javascript"
  16
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  17
+
  18
+  <body xmlns="http://www.w3.org/1999/xhtml">
  19
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=780908"
  20
+     target="_blank">Mozilla Bug 780908</a>
  21
+  <p/>
  22
+  <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  23
+          id="editor"
  24
+          type="content-primary"
  25
+          editortype="html"
  26
+          style="width: 400px; height: 100px; border: thin solid black"/>
  27
+  <p/>
  28
+  <pre id="test">
  29
+  </pre>
  30
+  </body>
  31
+  <script class="testbody" type="application/javascript">
  32
+  <![CDATA[
  33
+
  34
+  SimpleTest.waitForExplicitFinish();
  35
+
  36
+  function EditorContentListener(aEditor)
  37
+  {
  38
+    this.init(aEditor);
  39
+  }
  40
+  
  41
+  EditorContentListener.prototype = {
  42
+    init : function(aEditor)
  43
+      {
  44
+        this.mEditor = aEditor;
  45
+      },
  46
+  
  47
+    QueryInterface : function(aIID)
  48
+      {
  49
+        if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  50
+            aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  51
+            aIID.equals(Components.interfaces.nsISupports))
  52
+          return this;
  53
+        throw Components.results.NS_NOINTERFACE;
  54
+      },
  55
+  
  56
+    onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
  57
+    {
  58
+        if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
  59
+        {
  60
+          var editor = this.mEditor.getEditor(this.mEditor.contentWindow);
  61
+          if (editor) {
  62
+              this.mEditor.focus();
  63
+              editor instanceof Components.interfaces.nsIHTMLEditor;
  64
+              editor.returnInParagraphCreatesNewParagraph = true;
  65
+              source = "<html><body><table><head></table></body></html>";
  66
+              editor.rebuildDocumentFromSource(source);
  67
+              ok(true, "Don't crash when head appears after body");
  68
+              source = "<html></head><head><body></body></html>";
  69
+              editor.rebuildDocumentFromSource(source);
  70
+              ok(true, "Don't crash when /head appears before head");
  71
+              SimpleTest.finish();
  72
+              progress.removeProgressListener(this);
  73
+          }
  74
+        }
  75
+  
  76
+    },
  77
+  
  78
+  
  79
+    onProgressChange : function(aWebProgress, aRequest,
  80
+                                aCurSelfProgress, aMaxSelfProgress,
  81
+                                aCurTotalProgress, aMaxTotalProgress)
  82
+      {
  83
+      },
  84
+  
  85
+    onLocationChange : function(aWebProgress, aRequest, aLocation, aFlags)
  86
+      {
  87
+      },
  88
+  
  89
+    onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
  90
+      {
  91
+      },
  92
+  
  93
+    onSecurityChange : function(aWebProgress, aRequest, aState)
  94
+      {
  95
+      },
  96
+  
  97
+      mEditor: null
  98
+  };
  99
+
  100
+  var progress, progressListener;
  101
+
  102
+  function runTest() {
  103
+    var newEditorElement = document.getElementById("editor");
  104
+    newEditorElement.makeEditable("html", true);
  105
+    var docShell = newEditorElement.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).docShell;
  106
+    progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);
  107
+    progressListener = new EditorContentListener(newEditorElement);
  108
+    progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  109
+    newEditorElement.setAttribute("src", "data:text/html,");
  110
+  }
  111
+]]>
  112
+</script>
  113
+</window>

0 notes on commit 3558783

Please sign in to comment.
Something went wrong with that request. Please try again.