sebastienros / fluid

Fluid is an open-source .NET template engine based on the Liquid template language.
MIT License
1.41k stars 176 forks source link

Handle IConvertible case to return specific type FluidValues #612

Closed atthevergeof closed 9 months ago

atthevergeof commented 9 months ago

fixes #609

The JValue class does implement IConvertible, but in Fluid.Create, when System.Type.GetTypeCode() is called with JValue type in the argument, it returns TypeCode.Object. And under this case, it was going to the IFormattable case and being converted to string regardless of the underlying data type. But when JValue is cast to IConvertible and then the GetTypeCode() method is called on the object, it does return the correct type code corresponding to the underlying value.

So to resolve the issue #609, I have moved the IConvertible case above IFormattable, and also changed its implementation to extract the underlying value and call the Create method again with that value. To prevent any infinite recursion, I have explicitly handled the TypeCode.Object case by returning the string value for it.

lahma commented 9 months ago

You probably want to add some test cases to demonstrate what you have fixed and also to ensure nobody breaks the behavior you are after later on.

atthevergeof commented 9 months ago

Added a test case to validate the change