-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug/issue 263/prevent transform from modifying template parameter #273
base: master
Are you sure you want to change the base?
Bug/issue 263/prevent transform from modifying template parameter #273
Conversation
Sorry for delayed response, but this isn't a large priority for me, so I hardly look here. If you explain what you mean, I'll try to fix it sometime, though it may be more efficient (though less educational) if you simply take over the branch (I promise not to be offended.) |
There's this enum, EvaluationMode Something like this: [Flags]
public enum EvaluationMode : short
{
FallbackToDefault = 1,
AddOrReplaceProperties = 2,
Strict = 4,
CloneTransformer = 8,
} Context.Input = input;
JToken parentToken;
if ((Context.EvaluationMode & Context.EvaluationMode.CloneTransformer) == EvaluationMode.CloneTransformer)
{
if((transformer?.DeepClone()) is JObject transformerTemplate)
{
parentToken = (JToken)transformerTemplate;
}
else
{
throw new InvalidOperationException("Transformer could not be cloned successfully.");
}
}
else
{
parentToken = (JToken)transformer;
}
RecursiveEvaluate(ref parentToken, null, null, input);
return parentToken; Then when creating JsonTransformer: new JsonTransformer(new JUSTContext { EvaluationMode = EvaluationMode.CloneTransformer | EvaluationMode.<more options if needed> | EvaluationMode.<more options if needed> }) |
I see. This is something like a feature flag. Is there a plan for eventually deprecating the flags and folding these features in? |
Yes, like a feature flag. |
@Courela, |
As described in the bug ticket, the
Transform
method mutates thetransformer
parameter so if/when this value is reused, the latter values returned are incorrectly matched to the first input, instead of later input.By cloning the transformer before doing anything with it, it is the clone which gets mutated and the original
transformer
remains safe to reuse.