-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Use XML format in PlistParser #94863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jmagman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I swear I tried this a few years ago and hit some road block, but now I can't remember the details. Glad you're tackling it.
| return _parseXml(xmlContent); | ||
| } | ||
|
|
||
| Map<String, dynamic> _parseXml(String xmlContent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you convert all the dynamics in this file to Object or Object? while you're here? It was missed in the null safety migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| /// valid property list file, this will return null. | ||
| /// | ||
| /// The [plistFilePath] argument must not be null. | ||
| String? plistXmlContent(String plistFilePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is used outside this library.
| String? plistXmlContent(String plistFilePath) { | |
| String? _plistXmlContent(String plistFilePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually intend to override this internally to use plistutil so that PlistParser can be used on Linux.
| /// | ||
| /// The [plistFilePath] and [key] arguments must not be null. | ||
| String? getValueFromFile(String plistFilePath, String key) { | ||
| dynamic getValueFromFile(String plistFilePath, String key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handles all the valid plist xml types, but is not used except in getStringValueFromFile. Will it be used for something other than strings in g3? If not, we could get rid of this method and make getStringValueFromFile call:
plutil -extract $key raw -expect string $plistFilePath
instead of parsing the whole file. And we can implement other types as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be used for something other than strings in g3?
No. My intention is only to replace plutil (mac only) with plistutil (runs on linux).
If not, we could get rid of this method and make getStringValueFromFile call:
plutil -extract $key raw -expect string $plistFilePath
instead of parsing the whole file.
Getting rid of this method SGTM.
About calling plutil -extract for getStringValueFromFile, we already need to call plutil -convert for parseFile. I personally think it would be a better idea to consolidate the call to external tool in a single place, and plist files are generally small and parsing it is usually fast.
I've removed getValueFromFile and changed getStringValueFromFile to return parseFile(plistFilePath)[key] as String?. Do let me know if you still think we should use plutil -extract for getStringValueFromFile.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's a cheap operation. Let's keep it simple for the g3 case.
jmagman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cc @christopherfujino
Parse the Plist in XML format instead of JSON so that it can accept data that is not representable in JSON.
Move the part that reads the plist file content to a separate method so that it can be overridden to use a different tool other than plutil (which is Mac only).
Rename
getValueFromFiletogetStringValueFromFilenow that we have the ability to read value of any type from the plist file.Fixes #62160
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.