Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f72ee1f7
Commit
f72ee1f7
authored
Apr 29, 2015
by
Cesar Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle conversion of boolean query parameters with a value of "false"
parent
a2fe8a9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
conversion.go
pkg/runtime/conversion.go
+6
-2
conversion_test.go
pkg/runtime/conversion_test.go
+32
-0
No files found.
pkg/runtime/conversion.go
View file @
f72ee1f7
...
@@ -67,13 +67,17 @@ func convertStringSliceToInt(input *[]string, out *int, s conversion.Scope) erro
...
@@ -67,13 +67,17 @@ func convertStringSliceToInt(input *[]string, out *int, s conversion.Scope) erro
return
nil
return
nil
}
}
// converStringSliceToBool will convert a string parameter to boolean.
// Only the absence of a value, a value of "false", or a value of "0" resolve to false.
// Any other value (including empty string) resolves to true.
func
convertStringSliceToBool
(
input
*
[]
string
,
out
*
bool
,
s
conversion
.
Scope
)
error
{
func
convertStringSliceToBool
(
input
*
[]
string
,
out
*
bool
,
s
conversion
.
Scope
)
error
{
if
len
(
*
input
)
==
0
{
if
len
(
*
input
)
==
0
{
*
out
=
false
*
out
=
false
return
nil
}
}
switch
strings
.
ToLower
((
*
input
)[
0
])
{
switch
strings
.
ToLower
((
*
input
)[
0
])
{
case
"
true"
,
"1
"
:
case
"
false"
,
"0
"
:
*
out
=
tru
e
*
out
=
fals
e
default
:
default
:
*
out
=
true
*
out
=
true
}
}
...
...
pkg/runtime/conversion_test.go
View file @
f72ee1f7
...
@@ -29,6 +29,7 @@ type InternalComplex struct {
...
@@ -29,6 +29,7 @@ type InternalComplex struct {
Integer
int
Integer
int
Integer64
int64
Integer64
int64
Int64
int64
Int64
int64
Bool
bool
}
}
type
ExternalComplex
struct
{
type
ExternalComplex
struct
{
...
@@ -37,6 +38,7 @@ type ExternalComplex struct {
...
@@ -37,6 +38,7 @@ type ExternalComplex struct {
Integer
int
`json:"int"`
Integer
int
`json:"int"`
Integer64
int64
`json:",omitempty"`
Integer64
int64
`json:",omitempty"`
Int64
int64
Int64
int64
Bool
bool
`json:"bool"`
}
}
func
(
*
InternalComplex
)
IsAnAPIObject
()
{}
func
(
*
InternalComplex
)
IsAnAPIObject
()
{}
...
@@ -82,6 +84,36 @@ func TestStringMapConversion(t *testing.T) {
...
@@ -82,6 +84,36 @@ func TestStringMapConversion(t *testing.T) {
errFn
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
errFn
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
expected
:
&
ExternalComplex
{},
expected
:
&
ExternalComplex
{},
},
},
"parses boolean true"
:
{
input
:
map
[
string
][]
string
{
"bool"
:
{
"true"
},
},
expected
:
&
ExternalComplex
{
Bool
:
true
},
},
"parses boolean any value"
:
{
input
:
map
[
string
][]
string
{
"bool"
:
{
"foo"
},
},
expected
:
&
ExternalComplex
{
Bool
:
true
},
},
"parses boolean false"
:
{
input
:
map
[
string
][]
string
{
"bool"
:
{
"false"
},
},
expected
:
&
ExternalComplex
{
Bool
:
false
},
},
"parses boolean empty value"
:
{
input
:
map
[
string
][]
string
{
"bool"
:
{
""
},
},
expected
:
&
ExternalComplex
{
Bool
:
true
},
},
"parses boolean no value"
:
{
input
:
map
[
string
][]
string
{
"bool"
:
{},
},
expected
:
&
ExternalComplex
{
Bool
:
false
},
},
}
}
for
k
,
tc
:=
range
testCases
{
for
k
,
tc
:=
range
testCases
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment