@ -18,8 +18,10 @@ package cmd
import (
import (
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"reflect"
"reflect"
"strconv"
"strings"
"strings"
"time"
"time"
)
)
@ -34,16 +36,20 @@ func toString(val interface{}) string {
}
}
// toInteger _ Safely convert interface to integer without causing panic.
// toInteger _ Safely convert interface to integer without causing panic.
func toInteger ( val interface { } ) int64 {
func toInteger ( val interface { } ) ( int64 , error ) {
switch v := val . ( type ) {
switch v := val . ( type ) {
case float64 :
case float64 :
return int64 ( v )
return int64 ( v ) , nil
case int64 :
case int64 :
return v
return v , nil
case int :
case int :
return int64 ( v )
return int64 ( v ) , nil
case string :
i , err := strconv . Atoi ( v )
return int64 ( i ) , err
}
}
return 0
return 0 , errors . New ( "Invalid number format" )
}
}
// isString - Safely check if val is of type string without causing panic.
// isString - Safely check if val is of type string without causing panic.
@ -140,9 +146,19 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) {
Value : value ,
Value : value ,
}
}
case "content-length-range" :
case "content-length-range" :
min , err := toInteger ( condt [ 1 ] )
if err != nil {
return parsedPolicy , err
}
max , err := toInteger ( condt [ 2 ] )
if err != nil {
return parsedPolicy , err
}
parsedPolicy . Conditions . ContentLengthRange = contentLengthRange {
parsedPolicy . Conditions . ContentLengthRange = contentLengthRange {
Min : toInteger ( condt [ 1 ] ) ,
Min : min ,
Max : toInteger ( condt [ 2 ] ) ,
Max : max ,
Valid : true ,
Valid : true ,
}
}
default :
default :