Support Windows line endings in manifest files again (regression introduced in revision 5229353383b0). With test!
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 29 Jun 2010 13:16:43 -0400
changeset 47081 f0edfd2258ee68671ab37f128e9cebb747ff61be
parent 47080 1b9d6e37effe2c34429beaa0bb9862b12ce4c72c
child 47082 99ac7d16e904afa45cb09abff156760ab283cc0e
push idunknown
push userunknown
push dateunknown
milestone1.9.3a6pre
Support Windows line endings in manifest files again (regression introduced in revision 5229353383b0). With test!
chrome/test/unit/data/test_crlf.manifest
chrome/test/unit/test_crlf.js
xpcom/components/ManifestParser.cpp
new file mode 100644
--- /dev/null
+++ b/chrome/test/unit/data/test_crlf.manifest
@@ -0,0 +1,3 @@
+# Note: the following lines begins/end with a CR
+
+
content test_crlf . 
new file mode 100644
--- /dev/null
+++ b/chrome/test/unit/test_crlf.js
@@ -0,0 +1,15 @@
+registerManifests([do_get_file("data/test_crlf.manifest")]);
+
+function run_test()
+{
+  let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
+    getService(Ci.nsIChromeRegistry);
+
+  let ios = Cc["@mozilla.org/network/io-service;1"].
+    getService(Ci.nsIIOService);
+  let sourceURI = ios.newURI("chrome://test_crlf/content/", null, null);
+  // this throws for packages that are not registered
+  let file = cr.convertChromeURL(sourceURI).QueryInterface(Ci.nsIFileURL).file;
+  
+  do_check_true(file.equals(do_get_file("data/test_crlf.xul", true)));
+}
--- a/xpcom/components/ManifestParser.cpp
+++ b/xpcom/components/ManifestParser.cpp
@@ -111,17 +111,21 @@ static const ManifestDirective kParsingT
     NULL, &nsChromeRegistry::ManifestStyle },
   { "override",         2, true, true,  false,
     NULL, &nsChromeRegistry::ManifestOverride },
   { "resource",         2, true, true,  false,
     NULL, &nsChromeRegistry::ManifestResource }
 };
 
 static const char kWhitespace[] = "\t ";
-static const char kNewlines[]   = "\r\n";
+
+static bool IsNewline(char c)
+{
+  return c == '\n' || c == '\r';
+}
 
 namespace {
 struct AutoPR_smprintf_free
 {
   AutoPR_smprintf_free(char* buf)
     : mBuf(buf)
   {
   }
@@ -472,25 +476,25 @@ ParseManifest(NSLocationType aType, nsIL
   nsTArray<CachedDirective> contracts;
 
   char *token;
   char *newline = buf;
   PRUint32 line = 0;
 
   // outer loop tokenizes by newline
   while (*newline) {
-    while (*newline && '\n' == *newline) {
+    while (*newline && IsNewline(*newline)) {
       ++newline;
       ++line;
     }
     if (!*newline)
       break;
 
     token = newline;
-    while (*newline && '\n' != *newline)
+    while (*newline && !IsNewline(*newline))
       ++newline;
 
     if (*newline) {
       *newline = '\0';
       ++newline;
     }
     ++line;