jyruzicka / rubyfocus

A one-way (read-only) ruby bridge to OmniFocus.
28 stars 10 forks source link

`Psych` issue on newer Ruby versions #8

Closed andyw8 closed 10 months ago

andyw8 commented 1 year ago

:wave: Thank you for the great gem!

Just wanted to log an issue about a failure on newer versions of Ruby. It works fine in Ruby 2.7, but on 3.2 fails with:

/Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Rubyfocus::Document (Psych::DisallowedClass)
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/class_loader.rb:28:in `load'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:426:in `resolve_class'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:215:in `visit_Psych_Nodes_Mapping'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/visitor.rb:30:in `visit'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/visitor.rb:6:in `accept'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:35:in `accept'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:320:in `visit_Psych_Nodes_Document'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/visitor.rb:30:in `visit'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/visitor.rb:6:in `accept'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:35:in `accept'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych.rb:334:in `safe_load'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych.rb:369:in `load'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych.rb:671:in `block in load_file'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych.rb:670:in `open'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/psych.rb:670:in `load_file'
        from /Users/andy/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/rubyfocus-0.5.16/lib/rubyfocus/document.rb:64:in `load_from_file'

I believe this is due to changes in the Psych version that ships with Ruby, but I don't recall off-hand what version that happened in, possibly 3.0?

jyruzicka commented 1 year ago

Hi there! Unfortunately I don't maintain this gem these days. Should I update the readme to reflect this? Probably.

Anyway, if you're able to solve the issue yourself feel free to submit a pull request :D.

naupaka commented 1 year ago

Just chiming in to say I ran into this issue too. I think this is perhaps the clearest explanation of the change that I've read:

https://www.ctrl.blog/entry/ruby-psych4.html

I don't know much about Ruby so I could be wrong, but it seems like if you knew where to add the permitted_classes: bit then it should be a quick fix.

Basically the problem is that load_file now defaults to safe_load, which only permits a small number of classes (and doesn't include the Rubyfocus::Document class).

naupaka commented 1 year ago

Maybe here? https://github.com/jyruzicka/rubyfocus/blob/84d0b83360157a65340c501b0c4d20744e49be08/lib/rubyfocus/document.rb#L64

andyw8 commented 10 months ago

https://github.com/jyruzicka/rubyfocus/pull/9