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
71126e79
Commit
71126e79
authored
Oct 16, 2014
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't accept empty input in DecodeInto
parent
414ae795
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
0 deletions
+10
-0
decode.go
pkg/conversion/decode.go
+7
-0
scheme_test.go
pkg/conversion/scheme_test.go
+3
-0
No files found.
pkg/conversion/decode.go
View file @
71126e79
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
conversion
package
conversion
import
(
import
(
"errors"
"fmt"
"fmt"
"gopkg.in/v1/yaml"
"gopkg.in/v1/yaml"
...
@@ -73,6 +74,12 @@ func (s *Scheme) Decode(data []byte) (interface{}, error) {
...
@@ -73,6 +74,12 @@ func (s *Scheme) Decode(data []byte) (interface{}, error) {
// If obj's version doesn't match that in data, an attempt will be made to convert
// If obj's version doesn't match that in data, an attempt will be made to convert
// data into obj's version.
// data into obj's version.
func
(
s
*
Scheme
)
DecodeInto
(
data
[]
byte
,
obj
interface
{})
error
{
func
(
s
*
Scheme
)
DecodeInto
(
data
[]
byte
,
obj
interface
{})
error
{
if
len
(
data
)
==
0
{
// This is valid YAML, but it's a bad idea not to return an error
// for an empty string-- that's almost certainly not what the caller
// was expecting.
return
errors
.
New
(
"empty input"
)
}
dataVersion
,
dataKind
,
err
:=
s
.
DataVersionAndKind
(
data
)
dataVersion
,
dataKind
,
err
:=
s
.
DataVersionAndKind
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/conversion/scheme_test.go
View file @
71126e79
...
@@ -290,6 +290,9 @@ func TestBadJSONRejection(t *testing.T) {
...
@@ -290,6 +290,9 @@ func TestBadJSONRejection(t *testing.T) {
if
err
:=
s
.
DecodeInto
(
badJSONKindMismatch
,
&
TestType1
{});
err
==
nil
{
if
err
:=
s
.
DecodeInto
(
badJSONKindMismatch
,
&
TestType1
{});
err
==
nil
{
t
.
Errorf
(
"Kind is set but doesn't match the object type: %s"
,
badJSONKindMismatch
)
t
.
Errorf
(
"Kind is set but doesn't match the object type: %s"
,
badJSONKindMismatch
)
}
}
if
err
:=
s
.
DecodeInto
([]
byte
(
``
),
&
TestType1
{});
err
==
nil
{
t
.
Errorf
(
"Did not give error for empty data"
)
}
}
}
func
TestBadJSONRejectionForSetInternalVersion
(
t
*
testing
.
T
)
{
func
TestBadJSONRejectionForSetInternalVersion
(
t
*
testing
.
T
)
{
...
...
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