Stubble
Stubble copied to clipboard
Fix InterpolationTokenRenderer appending value without culture formatting
The value is only formatted for the correct culture if the token requests that the value is escaped (i.e. obj.EscapeResult
). Otherwise it just calls StringBuilder.Append()
with the raw value, which does not use the configured culture of our CompilationSettings
.
Benchmarks
I did not notice any meaningful difference in benchmarks. I included Nustache as a baseline.
Method | Index | Mean | Error | StdDev | Renderer | Gen 0 | Gen 1 | Allocated |
---|---|---|---|---|---|---|---|---|
Stubble_Before | 1 | 743.0 ns | 10.94 ns | 9.70 ns | Stubble | 0.4292 | 0.0038 | 3 KB |
Nustache_Before | 1 | 12,082.0 ns | 231.74 ns | 317.21 ns | Nustache | 3.6774 | 0.0916 | 23 KB |
Stubble_After | 1 | 725.8 ns | 11.44 ns | 10.70 ns | Stubble | 0.4292 | 0.0038 | 3 KB |
Nustache_After | 1 | 11,601.8 ns | 122.77 ns | 108.83 ns | Nustache | 3.6774 | 0.0916 | 23 KB |
Background
I noticed this issue because these two interpolation tests failed on my PC:
-
Triple Mustache Decimal Interpolation
-
Ampersand Decimal Interpolation
Expected: "1.21 jiggawatts!"
Actual: "1,21 jiggawatts!"
My PC has Swedish formatting settings and thus uses ,
instead of .
as a decimal separator.