Skip to content

Commit

Permalink
A colon should be only be split on if its followed by a space
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Mar 14, 2013
1 parent 6386b46 commit bc0d8eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
41 changes: 21 additions & 20 deletions yaml/parser.go
Expand Up @@ -208,8 +208,9 @@ func getType(line []byte) (typ, split int) {
return
}

typ = typScalar

if line[0] == ' ' || line[0] == '"' {
typ = typScalar
return
}

Expand All @@ -220,38 +221,38 @@ func getType(line []byte) (typ, split int) {

idx := bytes.IndexAny( line, " \":" )
if idx < 0 {
typ = typScalar
return
}

if line[idx] == '"' {
typ = typScalar
return
}

if line[idx] == ':' {
typ = typMapping
split = idx
return
}

// we have a space
// need to see if its all spaces until a :
for i := idx; i < len(line); i++ {
switch ch := line[i]; ch {
case ' ':
continue
case ':':
typ = typMapping
split = i
return
default:
typ = typScalar
return
} else if line[idx] == ' ' {
// we have a space
// need to see if its all spaces until a :
for i := idx; i < len(line); i++ {
switch ch := line[i]; ch {
case ' ':
continue
case ':':
typ = typMapping
split = i
break
default:
break
}
}
}

typ = typScalar
if typ == typMapping && split + 1 < len(line) && line[split+1] != ' ' {
typ = typScalar
split = 0
}

return
}

Expand Down
12 changes: 10 additions & 2 deletions yaml/parser_test.go
Expand Up @@ -14,8 +14,16 @@ var parseTests = []struct {
Output: "key1: val1\n",
},
{
Input: "key1 : val1\n",
Output: "key1: val1\n",
Input: "key2 : val1\n",
Output: "key2: val1\n",
},
{
Input: "key3:val1\n",
Output: "key3:val1\n",
},
{
Input: "key4 :val1\n",
Output: "key4 :val1\n",
},
{
Input: "key: nest: val\n",
Expand Down

0 comments on commit bc0d8eb

Please sign in to comment.