Skip to content

Commit 41ddff8

Browse files
authored
fixing bug where ':' was not allowed as a profile name (#235)
1 parent 27ba331 commit 41ddff8

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

internal/ini/ini_parser.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ var parseTable = map[ASTKind]map[TokenType]int{
8787
},
8888
ASTKindSectionStatement: map[TokenType]int{
8989
TokenLit: SectionState,
90+
TokenOp: SectionState,
9091
TokenSep: CloseScopeState,
91-
TokenWS: SkipTokenState,
92+
TokenWS: SectionState,
9293
TokenNL: SkipTokenState,
9394
},
9495
ASTKindCompletedSectionStatement: map[TokenType]int{
@@ -253,6 +254,26 @@ loop:
253254
return nil, NewParseError("expected ']'")
254255
}
255256

257+
// trim left hand side of spaces
258+
for i := 0; i < len(k.Root.raw); i++ {
259+
if !isWhitespace(k.Root.raw[i]) {
260+
break
261+
}
262+
263+
k.Root.raw = k.Root.raw[1:]
264+
i--
265+
}
266+
267+
// trim right hand side of spaces
268+
for i := len(k.Root.raw) - 1; i > 0; i-- {
269+
if !isWhitespace(k.Root.raw[i]) {
270+
break
271+
}
272+
273+
k.Root.raw = k.Root.raw[:len(k.Root.raw)-1]
274+
i--
275+
}
276+
256277
stack.Push(newCompletedSectionStatement(k))
257278
case SectionState:
258279
var stmt AST
@@ -268,7 +289,6 @@ loop:
268289
// the label of the section
269290
stmt = newSectionStatement(tok)
270291
case ASTKindSectionStatement:
271-
k.Root.raw = append(k.Root.raw, ' ')
272292
k.Root.raw = append(k.Root.raw, tok.Raw()...)
273293
stmt = k
274294
default:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[arn:aws:sts::1234:assumed-role/My-Role/session-name]
2+
region = "foo-region"
3+
arn = arn:aws:sts::1234:assumed-role/My-Role/session-name
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arn:aws:sts::1234:assumed-role/My-Role/session-name": {
3+
"region": "foo-region",
4+
"arn": "arn:aws:sts::1234:assumed-role/My-Role/session-name"
5+
}
6+
}

internal/ini/walker_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func TestDataFiles(t *testing.T) {
2424
{
2525
path: "./testdata/valid/simple_profile",
2626
},
27+
{
28+
path: "./testdata/valid/arn_profile",
29+
},
2730
{
2831
path: "./testdata/valid/commented_profile",
2932
},

0 commit comments

Comments
 (0)