Skip to content

Commit

Permalink
Expose a few key LoadSettings values
Browse files Browse the repository at this point in the history
These values are often set to mitigate DOS attacks, so we want to
expose them for JRuby users.

See ruby#579
  • Loading branch information
headius committed Jan 13, 2023
1 parent d772d8a commit 7bbe013
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ext/java/org/jruby/ext/psych/PsychParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -487,6 +488,42 @@ public IRubyObject mark(ThreadContext context) {
);
}

@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());
}

private LoadSettings buildSettings() {
return loadSettingsBuilder.build();
}
Expand Down

0 comments on commit 7bbe013

Please sign in to comment.