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
Transformmethod mutates thetransformerparameter 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
transformerremains safe to reuse.