ckruse / CFPropertyList

Read, write and manipulate both binary and XML property lists as defined by apple
MIT License
212 stars 47 forks source link

invalid byte sequence in US-ASCII #42

Closed ANTARESXXI closed 9 years ago

ANTARESXXI commented 9 years ago

/Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbCFPropertyList.rb:326:in `load_str'

ANTARESXXI commented 9 years ago

Other case:

/Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbPlainCFPropertyList.rb:43:in skip' /Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbPlainCFPropertyList.rb:43:inskip_whitespaces' /Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbPlainCFPropertyList.rb:177:in import_plain' /Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbPlainCFPropertyList.rb:24:inload' /Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbCFPropertyList.rb:375:in load' /Library/Ruby/Gems/2.0.0/gems/CFPropertyList-2.3.1/lib/cfpropertylist/rbCFPropertyList.rb:252:ininitialize'

ANTARESXXI commented 9 years ago

Here's the plist https://dl.dropboxusercontent.com/u/62285475/Info2.plist

It's ok with plutil -lint

ckruse commented 9 years ago

Can you show me the code you try to parse the plist with? It works flawlessly for me:

➜ ckruse@vali ~/dev/CFPropertyList (master) ✗ % curl -O https://dl.dropboxusercontent.com/u/62285475/Info2.plist
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4080  100  4080    0     0   4043      0  0:00:01  0:00:01 --:--:--  4047
➜ ckruse@vali ~/dev/CFPropertyList (master) ✗ % cat test.rb
#!/usr/bin/env ruby

require 'cfpropertylist'

list = CFPropertyList::List.new(file: './Info2.plist')
puts "properly parsed file"

# eof
➜ ckruse@vali ~/dev/CFPropertyList (master) ✗ % ruby -I./lib/ test.rb
properly parsed file
➜ ckruse@vali ~/dev/CFPropertyList (master) ✗ %

Also please show me the output of locale and ruby -e 'puts "".encoding.name'. It somewhat looks to me that you have a non-UTF-8 environment.

ANTARESXXI commented 9 years ago

First of all thanks for your quick response! I'm trying to make it via Jenkins CI, so

I tried both: plist = CFPropertyList::List.new plist.load_str(File.read(path)

and CFPropertyList::List.new(:file => path)

ckruse commented 9 years ago

Can you set a UTF-8 locale, e.g. LANG=en_US.UTF-8? It seems to me that Ruby tries to parse the CFPropertyList code as US-ASCII, despite the coding header in the source files.

ANTARESXXI commented 9 years ago

Sorry for stupid question but can I set UTF-8 locale for my entire gem and change it for all dependencies (like CFPropertyList, etc.) and external calls (system(), %x[], etc)? If yes then how? Unfortunately I'm not so skilled with ruby yet =)

ckruse commented 9 years ago

The locale has to be set by the User, you shouldn't set it in your code if you are writing a gem, only if you are coding an application. So in this case your Jenkins server should have a config option or your test should set it before calling the Ruby code.

Also ensure that you set a coding header in you source code:

# encoding: utf-8

This tells the Ruby interpreter that you source code is coded in UTF-8.

ANTARESXXI commented 9 years ago

Thanks for your help!

ckruse commented 9 years ago

So it works for you now? Just for my curiosity if I'm right or if I'm wrong

ANTARESXXI commented 9 years ago

My mac pc has: locale LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL=

and everything forks fine there. So Jenkins CI (running on the same mac pc) somehow uses it's own LC_CTYPE and that's the reason of my issue.

ckruse commented 9 years ago

Thanks!