Skip to content

Commit

Permalink
Fix for being too strict when accepting PLISTs and also fixes a regre…
Browse files Browse the repository at this point in the history
…ssion with erroring when parsing code with shebangs(!).

Closes cappuccino#69.

Reviewed by me.
  • Loading branch information
Francisco Ryan Tolmasky I committed Feb 3, 2010
1 parent 8284498 commit 21ef259
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Objective-J/CFPropertyList.js
Expand Up @@ -11,8 +11,9 @@ function CFPropertyList()
this._UID = generateObjectUID();
}

CFPropertyList.PLISTRE = /^\s*<\s*plist\s*>/i;
CFPropertyList.DTDRE = /^\s*<\?\s*xml\s+version\s*=\s*\"1.0\"[^>]*\?>\s*<\!DOCTYPE\s+plist\s+PUBLIC\s+\"-\/\/Apple(?:\sComputer)?\/\/DTD\s+PLIST\s+1.0\/\/EN\"\s+\"http:\/\/www\.apple\.com\/DTDs\/PropertyList-1\.0\.dtd\"\s*>/i;
// We are really liberal when accepting DOCTYPEs.
CFPropertyList.DTDRE = /^\s*(?:<\?\s*xml\s+version\s*=\s*\"1.0\"[^>]*\?>\s*)?(?:<\!DOCTYPE[^>]*>\s*)?/i
CFPropertyList.XMLRE = /^\s*(?:<\?\s*xml\s+version\s*=\s*\"1.0\"[^>]*\?>\s*)?(?:<\!DOCTYPE[^>]*>\s*)?<\s*plist[^>]*\>/i;

CFPropertyList.FormatXMLDTD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">";
CFPropertyList.Format280NorthMagicNumber = "280NPLIST";
Expand All @@ -26,12 +27,8 @@ CFPropertyList.Format280North_v1_0 = -1000;

CFPropertyList.sniffedFormatOfString = function(/*String*/ aString)
{
// If the string starts with the plist DTD
if (aString.match(CFPropertyList.DTDRE))
return CFPropertyList.FormatXML_v1_0;

// If the string starts with <plist>...
if (aString.match(CFPropertyList.PLISTRE))
// Check if this is an XML Plist.
if (aString.match(CFPropertyList.XMLRE))
return CFPropertyList.FormatXML_v1_0;

if (aString.substr(0, CFPropertyList.Format280NorthMagicNumber.length) === CFPropertyList.Format280NorthMagicNumber)
Expand Down Expand Up @@ -456,6 +453,7 @@ function parseXML(/*String*/ aString)
{
XMLNode = new ActiveXObject("Microsoft.XMLDOM");

// Extract the DTD, which confuses IE.
var matches = aString.match(CFPropertyList.DTDRE);

if (matches)
Expand Down
1 change: 1 addition & 0 deletions Objective-J/CommonJS/lib/objective-j/loader.js
Expand Up @@ -9,6 +9,7 @@ function ObjectiveJLoader() {

//print("loading objective-j: " + topId + " (" + path + ")");
factories[topId] = objj.make_narwhal_factory(path);
factories[topId].path = path;
}

loader.load = function(topId, path) {
Expand Down
3 changes: 3 additions & 0 deletions Objective-J/Preprocessor.js
Expand Up @@ -143,6 +143,9 @@ function preprocess(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)

function Preprocessor(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)
{
// Remove the shebang.
aString = aString.replace(/^#[^\n]+\n/, "\n");

this._currentSelector = "";
this._currentClass = "";
this._currentSuperClass = "";
Expand Down
17 changes: 17 additions & 0 deletions Tests/Objective-J/CFPropertyListTest.j
@@ -0,0 +1,17 @@

var FILE = require("file"),
FileList = require("jake").FileList;

@implementation CFPropertyListTest : OJTestCase

- (void)testFormatSniffing
{
var XMLPropertyLists = new FileList(FILE.join(FILE.dirname(module.path), "PropertyLists", "XML-*.plist"));

XMLPropertyLists.forEach(function(/*String*/ aPath)
{
[self assert:CFPropertyList.FormatXML_v1_0 equals:CFPropertyList.sniffedFormatOfString(FILE.read(aPath))];
});
}

@end
4 changes: 4 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-0.plist
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict/>
</plist>
5 changes: 5 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-1.plist
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
4 changes: 4 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-2.plist
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict/>
</plist>
4 changes: 4 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-3.plist
@@ -0,0 +1,4 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
3 changes: 3 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-4.plist
@@ -0,0 +1,3 @@
<plist version="1.0">
<dict/>
</plist>
7 changes: 7 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-5.plist
@@ -0,0 +1,7 @@




<plist version="1.0">
<dict/>
</plist>
7 changes: 7 additions & 0 deletions Tests/Objective-J/PropertyLists/XML-6.plist
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>



<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">
<dict/>
</plist>

0 comments on commit 21ef259

Please sign in to comment.