Skip to content

Commit

Permalink
fixing bug where ':' was not valid in the profile (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
xibz authored Nov 1, 2018
1 parent a76d905 commit 465c259
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
24 changes: 22 additions & 2 deletions internal/ini/ini_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ var parseTable = map[ASTKind]map[TokenType]int{
},
ASTKindSectionStatement: map[TokenType]int{
TokenLit: SectionState,
TokenOp: SectionState,
TokenSep: CloseScopeState,
TokenWS: SkipTokenState,
TokenWS: SectionState,
TokenNL: SkipTokenState,
},
ASTKindCompletedSectionStatement: map[TokenType]int{
Expand Down Expand Up @@ -253,6 +254,26 @@ loop:
return nil, NewParseError("expected ']'")
}

// trim left hand side of spaces
for i := 0; i < len(k.Root.raw); i++ {
if !isWhitespace(k.Root.raw[i]) {
break
}

k.Root.raw = k.Root.raw[1:]
i--
}

// trim right hand side of spaces
for i := len(k.Root.raw) - 1; i > 0; i-- {
if !isWhitespace(k.Root.raw[i]) {
break
}

k.Root.raw = k.Root.raw[:len(k.Root.raw)-1]
i--
}

stack.Push(newCompletedSectionStatement(k))
case SectionState:
var stmt AST
Expand All @@ -268,7 +289,6 @@ loop:
// the label of the section
stmt = newSectionStatement(tok)
case ASTKindSectionStatement:
k.Root.raw = append(k.Root.raw, ' ')
k.Root.raw = append(k.Root.raw, tok.Raw()...)
stmt = k
default:
Expand Down
3 changes: 3 additions & 0 deletions internal/ini/testdata/valid/arn_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[arn:aws:sts::1234:assumed-role/My-Role/session-name]
region = "foo-region"
arn = arn:aws:sts::1234:assumed-role/My-Role/session-name
6 changes: 6 additions & 0 deletions internal/ini/testdata/valid/arn_profile_expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arn:aws:sts::1234:assumed-role/My-Role/session-name": {
"region": "foo-region",
"arn": "arn:aws:sts::1234:assumed-role/My-Role/session-name"
}
}
3 changes: 3 additions & 0 deletions internal/ini/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func TestDataFiles(t *testing.T) {
{
path: "./testdata/valid/simple_profile",
},
{
path: "./testdata/valid/arn_profile",
},
{
path: "./testdata/valid/commented_profile",
},
Expand Down

0 comments on commit 465c259

Please sign in to comment.