Bug 649134 - Ignore an empty or whitespace only href in the Link HTTP header. r=bzbarsky
authorMats Palmgren <matspal@gmail.com>
Wed, 11 May 2011 11:46:59 +0200
changeset 69321 f3c01fd55b6b37ad477db4cf52e9ddd02b79d47a
parent 69320 a5b0d8686c97ef1745fb1704598be4912ee4ddc4
child 69322 86849e5fb7ca9ddc77026a941358611866ab1410
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs649134
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 649134 - Ignore an empty or whitespace only href in the Link HTTP header. r=bzbarsky
content/base/src/nsContentSink.cpp
content/html/content/test/Makefile.in
content/html/content/test/bug649134/Makefile.in
content/html/content/test/bug649134/file_bug649134-1.sjs
content/html/content/test/bug649134/file_bug649134-2.sjs
content/html/content/test/bug649134/index.html
content/html/content/test/test_bug649134.html
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -701,30 +701,32 @@ nsContentSink::ProcessLinkHeader(nsICont
           }
         }
       }
     }
 
     if (endCh == kCommaCh) {
       // hit a comma, process what we've got so far
 
+      href.Trim(" \t\n\r\f"); // trim HTML5 whitespace
       if (!href.IsEmpty() && !rel.IsEmpty()) {
         rv = ProcessLink(aElement, href, rel, title, type, media);
       }
 
       href.Truncate();
       rel.Truncate();
       title.Truncate();
       type.Truncate();
       media.Truncate();
     }
 
     start = ++end;
   }
 
+  href.Trim(" \t\n\r\f"); // trim HTML5 whitespace
   if (!href.IsEmpty() && !rel.IsEmpty()) {
     rv = ProcessLink(aElement, href, rel, title, type, media);
   }
 
   return rv;
 }
 
 
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -37,16 +37,21 @@
 
 DEPTH          = ../../../..
 topsrcdir      = @top_srcdir@
 srcdir         = @srcdir@
 VPATH          = @srcdir@
 relativesrcdir = content/html/content/test
 
 include $(DEPTH)/config/autoconf.mk
+
+ifdef ENABLE_TESTS
+DIRS		+= bug649134
+endif
+
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
 		test_hidden.html \
 		test_bug589.html \
 		test_bug691.html \
 		nnc_lockup.gif \
 		test_bug694.html \
@@ -258,12 +263,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug636336.html \
 		test_bug630889.html \
 		test_bug610212.html \
 		test_bug633058.html \
 		test_bug641219.html \
 		test_bug643051.html \
 		test_bug583514.html \
 		test_bug514437.html \
+		test_bug649134.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/bug649134/Makefile.in
@@ -0,0 +1,50 @@
+#
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is mozilla.org code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla Foundation.
+# Portions created by the Initial Developer are Copyright (C) 2011
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either of the GNU General Public License Version 2 or later (the "GPL"),
+# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH          = ../../../../..
+topsrcdir      = @top_srcdir@
+srcdir         = @srcdir@
+VPATH          = @srcdir@
+relativesrcdir = content/html/content/test/bug649134
+
+include $(DEPTH)/config/autoconf.mk
+include $(topsrcdir)/config/rules.mk
+
+_TEST_FILES = file_bug649134-1.sjs file_bug649134-2.sjs index.html
+
+libs:: $(_TEST_FILES)
+	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/bug649134/file_bug649134-1.sjs
@@ -0,0 +1,12 @@
+function handleRequest(request, response)
+{
+  response.seizePower();
+  var r = 'HTTP/1.1 200 OK\r\n' +
+          'Content-Type: text/html\r\n' +
+          'Link: <		\014>; rel="stylesheet"\r\n' +
+          '\r\n' +
+          '<!-- selector {} body {display:none;} --><body>PASS</body>\r\n';
+  response.bodyOutputStream.write(r, r.length);
+  response.bodyOutputStream.flush();
+  response.finish();
+}
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/bug649134/file_bug649134-2.sjs
@@ -0,0 +1,12 @@
+function handleRequest(request, response)
+{
+  response.seizePower();
+  var r = 'HTTP/1.1 200 OK\r\n' +
+          'Content-Type: text/html\r\n' +
+          'Link: <		\014>; rel="stylesheet",\r\n' +
+          '\r\n' +
+          '<!-- selector {} body {display:none;} --><body>PASS</body>\r\n';
+  response.bodyOutputStream.write(r, r.length);
+  response.bodyOutputStream.flush();
+  response.finish();
+}
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/bug649134/index.html
@@ -0,0 +1,3 @@
+body {
+    display:none;
+}
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_bug649134.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=649134
+-->
+<head>
+  <title>Test for Bug 649134</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=649134">Mozilla Bug 649134</a>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 649134 **/
+SimpleTest.waitForExplicitFinish();
+
+var calls = 0;
+function finish() {
+  if (++calls == 4)
+    SimpleTest.finish();
+}
+function verifyNoLoad(iframe) {
+  ok(iframe.contentDocument.body.offsetHeight > 0,
+     "HTTP Link stylesheet was ignored " + iframe.src);
+  finish();
+}
+var verifyLoadCalls = 0;
+function verifyLoad(iframe) {
+  if (++verifyLoadCalls == 2) {
+    ok(indexContent == iframe.contentDocument.body.innerHTML,
+       "bug649134/ loads bug649134/index.html " + iframe.src);
+  }
+  finish();
+}
+function indexLoad(iframe) {
+  indexContent = iframe.contentDocument.body.innerHTML;
+  verifyLoad(iframe);
+}
+
+</script>
+</pre>
+<p id="display">
+<!-- Note: the extra sub-directory is needed for the test, see bug 649134 comment 14 -->
+<iframe onload="verifyNoLoad(this);" src="bug649134/file_bug649134-1.sjs"></iframe>
+<iframe onload="verifyNoLoad(this);" src="bug649134/file_bug649134-2.sjs"></iframe>
+<iframe onload="verifyLoad(this);" src="bug649134/"></iframe> <!-- verify that mochitest server loads index.html -->
+<iframe onload="indexLoad(this);" src="bug649134/index.html"></iframe>
+</p>
+</body>
+</html>