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
919bb01b
Commit
919bb01b
authored
Oct 07, 2016
by
AdoHe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix yaml decode issue
parent
56be1976
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
11 deletions
+23
-11
decoder.go
pkg/util/yaml/decoder.go
+19
-7
decoder_test.go
pkg/util/yaml/decoder_test.go
+4
-4
No files found.
pkg/util/yaml/decoder.go
View file @
919bb01b
...
...
@@ -137,7 +137,7 @@ func (d *YAMLDecoder) Close() error {
}
const
yamlSeparator
=
"
\n
---"
const
separator
=
"---
\n
"
const
separator
=
"---"
// splitYAMLDocument is a bufio.SplitFunc for splitting YAML streams into individual documents.
func
splitYAMLDocument
(
data
[]
byte
,
atEOF
bool
)
(
advance
int
,
token
[]
byte
,
err
error
)
{
...
...
@@ -246,16 +246,28 @@ func (r *YAMLReader) Read() ([]byte, error) {
return
nil
,
err
}
if
string
(
line
)
==
separator
||
err
==
io
.
EOF
{
sep
:=
len
([]
byte
(
separator
))
if
i
:=
bytes
.
Index
(
line
,
[]
byte
(
separator
));
i
==
0
{
// We have a potential document terminator
i
+=
sep
after
:=
line
[
i
:
]
if
len
(
strings
.
TrimRightFunc
(
string
(
after
),
unicode
.
IsSpace
))
==
0
{
if
buffer
.
Len
()
!=
0
{
return
buffer
.
Bytes
(),
nil
}
if
err
==
io
.
EOF
{
return
nil
,
err
}
}
}
if
err
==
io
.
EOF
{
if
buffer
.
Len
()
!=
0
{
// If we're at EOF, we have a final, non-terminated line. Return it.
return
buffer
.
Bytes
(),
nil
}
if
err
==
io
.
EOF
{
return
nil
,
err
}
}
else
{
buffer
.
Write
(
line
)
return
nil
,
err
}
buffer
.
Write
(
line
)
}
}
...
...
pkg/util/yaml/decoder_test.go
View file @
919bb01b
...
...
@@ -106,7 +106,7 @@ func TestDecodeYAML(t *testing.T) {
s
:=
NewYAMLToJSONDecoder
(
bytes
.
NewReader
([]
byte
(
`---
stuff: 1
---
---
`
)))
obj
:=
generic
{}
if
err
:=
s
.
Decode
(
&
obj
);
err
!=
nil
{
...
...
@@ -138,11 +138,11 @@ stuff: 1
obj
:=
generic
{}
err
:=
s
.
Decode
(
&
obj
)
if
err
==
nil
{
t
.
Fatal
(
"expected error with yaml:
prefix
, got no error"
)
t
.
Fatal
(
"expected error with yaml:
violate
, got no error"
)
}
fmt
.
Printf
(
"err: %s
\n
"
,
err
.
Error
())
if
!
strings
.
HasPrefix
(
err
.
Error
(),
"yaml: line
1
:"
)
{
t
.
Fatalf
(
"expected %q to have 'yaml: line
1:' prefix
"
,
err
.
Error
())
if
!
strings
.
HasPrefix
(
err
.
Error
(),
"yaml: line
2
:"
)
{
t
.
Fatalf
(
"expected %q to have 'yaml: line
2:' found a tab character
"
,
err
.
Error
())
}
}
...
...
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