Skip to content

Add Mail::YAML#load compatible with Psych 3.x and Psych 4.x.#1476

Closed
simi wants to merge 1 commit intomikel:masterfrom
RubyElders:psych-4-compat
Closed

Add Mail::YAML#load compatible with Psych 3.x and Psych 4.x.#1476
simi wants to merge 1 commit intomikel:masterfrom
RubyElders:psych-4-compat

Conversation

@simi
Copy link
Contributor

@simi simi commented Mar 23, 2022

This is 1:1 transition. It would be great to be able to use "safe" load, but since custom classes could be serialised, it is not easily possible for now.

Btw. the best would be to be able to migrate to Psych 4, but it seems impossible since EOL Rubies are supported.

@voxik @deivid-rodriguez

@voxik
Copy link
Contributor

voxik commented Mar 24, 2022

Very nice. Thx. This fixes the compatibility. Since there is check for the delivery_handler, I don't feel very bad about usa of the unsafe_load.

@voxik
Copy link
Contributor

voxik commented Mar 24, 2022

Since there is check for the delivery_handler, I don't feel very bad about usa of the unsafe_load.

Hm, this is probably not very relevant 🙄 Nevertheless, how about:

$ git diff
diff --git a/lib/mail/yaml.rb b/lib/mail/yaml.rb
index c0910855..b70da033 100644
--- a/lib/mail/yaml.rb
+++ b/lib/mail/yaml.rb
@@ -2,15 +2,23 @@ require 'yaml'
 
 module Mail
   module YAML
-    # unsafe loading compatible with Psych 3.x and Psych 4.x
-    if ::YAML.respond_to?(:unsafe_load)
-      def self.load(yaml)
-        ::YAML.unsafe_load(yaml)
-      end
-    else
-      def self.load(yaml)
-        ::YAML.load(yaml)
-      end
+    def self.load(yaml)
+      ::YAML.load(yaml, :permitted_classes => [
+        Symbol,
+
+        Mail::Body,
+
+        # Delivery methods as listed in mail/configuration.rb
+        Mail::SMTP,
+        Mail::Sendmail,
+        Mail::Exim,
+        Mail::FileDelivery,
+        Mail::SMTPConnection,
+        Mail::TestMailer,
+        Mail::LoggerDelivery,
+
+        Mail.delivery_method.class,
+      ])
     end
   end
 end

@mikel
Copy link
Owner

mikel commented Apr 19, 2022

Hey there @voxik thanks for the help on creating this. I just kicked off the workflows and looks like we have some failures on 1.9, 2.0, 2.2, 2.7 and latest. Can you take a quick look at those and see if we can fix those up? cc @deivid-rodriguez

@mikel
Copy link
Owner

mikel commented Apr 19, 2022

Sorry I'm late to the party :) Happy to help get these 3.x PRs resolved and merged and a new gem released asap.

@deivid-rodriguez
Copy link
Contributor

My recall about current failures from working on #1472:

  • The one on Ruby 2.7 is an existing flaky failure that happens randomly on different rubies. Restarting should "fix it".
  • The failures on older rubies I think are already happening on master, and Add Ruby 3.1 support #1472 is dropping support anyways.

So I think this PR should be fine!

@deivid-rodriguez
Copy link
Contributor

@mikel I unified changes from #1472 and this PR to get a base green CI at #1478. It would make this PR unnecessary (I kept proper attribution to @simi and @voxik at #1478).

Then I can rebase #1472 to take care of adding Ruby 3.1 support.

What do you think?

@simi simi closed this Apr 21, 2022
@simi simi deleted the psych-4-compat branch April 21, 2022 11:47
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

Successfully merging this pull request may close these issues.

4 participants