Use internal default as fallback for global options #160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran into this issue in a situation where we're evaluating semi-trusted user input where we want to be careful that the user cannot change external settings. As a result, we're carefully scrubbing and restoring the state of global option after evaluating the user input. Unfortunately, this led me to an issue where
diffobj
(and alsofansi
) set global options on load that may later removed and break package functionality.Here's a simple reprex. Run a function that attaches diffobj, but where options are protected.
Yes, the options are protected a little aggressively, restoring unset options to their original state...
with the side-effect of removing the
diffobj.max.diffs
option...breaking any subsequent call to
ses()
.(Something similar happens for
diffobj.warn
.)The solution I'm proposing is to fall back to the internal diffobj default value in
gdo()
. I think this is reasonable since I think it doesn't change the intended behavior and it matches the expectations described in the documentation:I recognize I haven't completely though through all of the implications, if there are any broader problems please feel free to treat this PR as an issue report 😄