cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.17k stars 7.05k forks source link

plist files created by FileUtils are invalid xml (except iOS/macOS) #20602

Open cigumo opened 3 years ago

cigumo commented 3 years ago

cocos2d-x version:3 and 4

Steps to Reproduce:

The problem shows up when you share save games between mac and windows. Those created on Windows will not be read on Mac because they're invalid xml.

This is the patch:

modified   cocos/platform/CCFileUtils.cpp
@@ -373,7 +373,7 @@ bool FileUtils::writeValueMapToFile(const ValueMap& dict, const std::string& ful
     }

     doc->LinkEndChild(declaration);
-    tinyxml2::XMLElement *docType = doc->NewElement("!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
+    tinyxml2::XMLUnknown *docType = doc->NewUnknown("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
     doc->LinkEndChild(docType);

     tinyxml2::XMLElement *rootEle = doc->NewElement("plist");
@@ -413,7 +413,7 @@ bool FileUtils::writeValueVectorToFile(const ValueVector& vecData, const std::st
     }

     doc->LinkEndChild(declaration);
-    tinyxml2::XMLElement *docType = doc->NewElement("!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
+    tinyxml2::XMLUnknown *docType = doc->NewUnknown("DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
     doc->LinkEndChild(docType);

     tinyxml2::XMLElement *rootEle = doc->NewElement("plist");
rh101 commented 3 years ago

Is the exclamation mark prefix automatically added by NewUnknown(...)?

cigumo commented 3 years ago

Yes

rh101 commented 3 years ago

Are you able to create pull request with the fix?

cigumo commented 3 years ago

It's just two lines :)

rh101 commented 3 years ago

I realise it's only a few lines, and the reason I asked was more to do with visibility and the chances of it being fixed within a reasonable amount of time. Note the 1300+ issues and ~180 pull requests at the time of this post.