Skip to content
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

Cannot parse some sort of NeXT Step style Property List #67

Open
manicmaniac opened this issue Feb 25, 2024 · 1 comment
Open

Cannot parse some sort of NeXT Step style Property List #67

manicmaniac opened this issue Feb 25, 2024 · 1 comment

Comments

@manicmaniac
Copy link

manicmaniac commented Feb 25, 2024

CFPropertyList::List raises an error when the following types of Property List.

1. Dictionary without surrounding { }

require 'cfpropertylist'

data = 'foo = bar;'
CFPropertyList::List.new(data: data)
/path/to/CFPropertyList-3.0.7/lib/cfpropertylist/rbPlainCFPropertyList.rb:25:in `load': content after root object (CFFormatError)
	from /path/to/CFPropertyList-3.0.7/lib/cfpropertylist/rbCFPropertyList.rb:321:in `load_str'
	from /path/to/CFPropertyList-3.0.7/lib/cfpropertylist/rbCFPropertyList.rb:239:in `initialize'
	from /var/folders/tm/wy8sj46s6yq4rlfgsxyvd1l80000gn/T/vdeL7YX/205:5:in `new'
	from /var/folders/tm/wy8sj46s6yq4rlfgsxyvd1l80000gn/T/vdeL7YX/205:5:in `<main>'

I cannot find the specification but I think it is a valid format because of some reasons.

  1. plutil can parse it.
$ echo 'foo = bar;' | plutil -p -
{
  "foo" => "bar"
}
  1. pl can parse it.
$ echo 'foo = bar;' | pl
{
    foo = bar;
}
  1. Foundation classes can parse it.
import Foundation

try! "foo = bar;".write(toFile: "foobar.plist", atomically: false, encoding: .utf8)
print(NSDictionary(contentsOfFile: "foobar.plist")!)
// prints
// {
//     foo = bar;
// }

And also, .strings format, which is often used as iOS localized string file, is encoded as this kind of Property List.

Whitespaces at the end

require 'cfpropertylist'

data = "foo\n"
CFPropertyList::List.new(data: data)
/path/to/CFPropertyList-3.0.7/lib/cfpropertylist/rbPlainCFPropertyList.rb:25:in `load': content after root object (CFFormatError)
	from /path/to/CFPropertyList-3.0.7/lib/cfpropertylist/rbCFPropertyList.rb:321:in `load_str'
	from /path/to/CFPropertyList-3.0.7/lib/cfpropertylist/rbCFPropertyList.rb:239:in `initialize'
	from /var/folders/tm/wy8sj46s6yq4rlfgsxyvd1l80000gn/T/vdeL7YX/188:5:in `new'
	from /var/folders/tm/wy8sj46s6yq4rlfgsxyvd1l80000gn/T/vdeL7YX/188:5:in `<main>'

I think it is also valid because of the following reasons.

  1. plutil can parse it.
$ printf 'foo\n' | plutil -p -
"foo"
  1. pl can parse it.
$ printf 'foo\n' | pl
foo
  1. Foundation classes can parse it.
import Foundation

try! "foo\n".write(toFile: "foobar.plist", atomically: false, encoding: .utf8)
print(try! NSString(contentsOfFile: "foobar.plist", encoding: String.Encoding.utf8.rawValue))
// prints foo
@ckruse
Copy link
Owner

ckruse commented Feb 25, 2024

I‘m seriously surprised that there are still people using this format.

Thank you for your report. Sadly I won‘t find the time to have a look at it today, but I will have a look at it in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants