mirror of
https://github.com/danog/liquid.git
synced 2024-12-02 10:17:48 +01:00
1. fix
This commit is contained in:
parent
e0ae1590bf
commit
dd12222409
@ -2,6 +2,7 @@ package liquid
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
@ -42,13 +43,14 @@ func TestEngine_ParseAndRenderString_ptr_to_hash(t *testing.T) {
|
|||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"message": &map[string]interface{}{
|
"message": &map[string]interface{}{
|
||||||
"Text": "hello",
|
"Text": "hello",
|
||||||
|
"jsonNumber" : json.Number("123"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
engine := NewEngine()
|
engine := NewEngine()
|
||||||
template := "{{ message.Text }}"
|
template := "{{ message.Text }} {{message.jsonNumber}}"
|
||||||
str, err := engine.ParseAndRenderString(template, params)
|
str, err := engine.ParseAndRenderString(template, params)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "hello", str)
|
require.Equal(t, "hello 123", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
type testStruct struct{ Text string }
|
type testStruct struct{ Text string }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package values
|
package values
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -44,6 +45,13 @@ func convertValueToInt(value interface{}, typ reflect.Type) (int64, error) {
|
|||||||
return 0, conversionError("", value, typ)
|
return 0, conversionError("", value, typ)
|
||||||
}
|
}
|
||||||
return v, nil
|
return v, nil
|
||||||
|
case json.Number:
|
||||||
|
v, err := strconv.ParseInt(value.String(), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, conversionError("", value, typ)
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0, conversionError("", value, typ)
|
return 0, conversionError("", value, typ)
|
||||||
}
|
}
|
||||||
@ -57,6 +65,12 @@ func convertValueToFloat(value interface{}, typ reflect.Type) (float64, error) {
|
|||||||
return 0, conversionError("", value, typ)
|
return 0, conversionError("", value, typ)
|
||||||
}
|
}
|
||||||
return v, nil
|
return v, nil
|
||||||
|
case json.Number:
|
||||||
|
v, err := strconv.ParseFloat(value.String(), 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, conversionError("", value, typ)
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
}
|
}
|
||||||
return 0, conversionError("", value, typ)
|
return 0, conversionError("", value, typ)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user