diff options
author | Charles Oliver Nutter <headius@headius.com> | 2023-01-13 08:48:44 -0600 |
---|---|---|
committer | Charles Oliver Nutter <headius@headius.com> | 2023-01-13 10:12:09 -0600 |
commit | a0e52470ede0bfe3cf629c6f8a6ca0c13c5face7 (patch) | |
tree | 5028e5c59b1d1e193e422a06f8cd49e07ef11728 | |
parent | 63428e345c6255a37a59c258dc0b7d1269ccf5f5 (diff) | |
download | psych-a0e52470ede0bfe3cf629c6f8a6ca0c13c5face7.tar.gz |
Expose a few key LoadSettings values
These values are often set to mitigate DOS attacks, so we want to
expose them for JRuby users.
See #579
-rw-r--r-- | ext/java/org/jruby/ext/psych/PsychParser.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ext/java/org/jruby/ext/psych/PsychParser.java b/ext/java/org/jruby/ext/psych/PsychParser.java index fd5e19c..279b3d9 100644 --- a/ext/java/org/jruby/ext/psych/PsychParser.java +++ b/ext/java/org/jruby/ext/psych/PsychParser.java @@ -34,6 +34,7 @@ import org.jcodings.specific.UTF8Encoding; import org.jcodings.unicode.UnicodeEncoding; import org.jruby.Ruby; import org.jruby.RubyArray; +import org.jruby.RubyBoolean; import org.jruby.RubyClass; import org.jruby.RubyEncoding; import org.jruby.RubyFixnum; @@ -488,6 +489,54 @@ public class PsychParser extends RubyObject { ); } + @JRubyMethod(name = "max_aliases_for_collections=") + public IRubyObject max_aliases_for_collections_set(IRubyObject max) { + loadSettingsBuilder.setMaxAliasesForCollections(max.convertToInteger().getIntValue()); + + return max; + } + + @JRubyMethod(name = "max_aliases_for_collections") + public IRubyObject max_aliases_for_collections(ThreadContext context) { + return context.runtime.newFixnum(buildSettings().getMaxAliasesForCollections()); + } + + @JRubyMethod(name = "allow_duplicate_keys=") + public IRubyObject allow_duplicate_keys_set(IRubyObject allow) { + loadSettingsBuilder.setAllowDuplicateKeys(allow.isTrue()); + + return allow; + } + + @JRubyMethod(name = "allow_duplicate_keys") + public IRubyObject allow_duplicate_keys(ThreadContext context) { + return RubyBoolean.newBoolean(context, buildSettings().getAllowDuplicateKeys()); + } + + @JRubyMethod(name = "allow_recursive_keys=") + public IRubyObject allow_recursive_keys_set(IRubyObject allow) { + loadSettingsBuilder.setAllowRecursiveKeys(allow.isTrue()); + + return allow; + } + + @JRubyMethod(name = "allow_recursive_keys") + public IRubyObject allow_recursive_keys(ThreadContext context) { + return RubyBoolean.newBoolean(context, buildSettings().getAllowRecursiveKeys()); + } + + @JRubyMethod(name = "code_point_limit=") + public IRubyObject code_point_limit_set(IRubyObject limit) { + loadSettingsBuilder.setCodePointLimit(limit.convertToInteger().getIntValue()); + + return limit; + } + + @JRubyMethod(name = "code_point_limit") + public IRubyObject code_point_limit(ThreadContext context) { + return context.runtime.newFixnum(buildSettings().getCodePointLimit()); + } + private LoadSettings buildSettings() { return loadSettingsBuilder.build(); } |