diff --git a/internal/ini/ini_parser.go b/internal/ini/ini_parser.go index a43127df94d..3ea751a98f8 100644 --- a/internal/ini/ini_parser.go +++ b/internal/ini/ini_parser.go @@ -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{ @@ -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 @@ -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: diff --git a/internal/ini/testdata/valid/arn_profile b/internal/ini/testdata/valid/arn_profile new file mode 100644 index 00000000000..d8c889ff7a6 --- /dev/null +++ b/internal/ini/testdata/valid/arn_profile @@ -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 diff --git a/internal/ini/testdata/valid/arn_profile_expected b/internal/ini/testdata/valid/arn_profile_expected new file mode 100644 index 00000000000..3b6a4da4a9b --- /dev/null +++ b/internal/ini/testdata/valid/arn_profile_expected @@ -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" + } +} diff --git a/internal/ini/walker_test.go b/internal/ini/walker_test.go index e350a2930d8..ecde710dead 100644 --- a/internal/ini/walker_test.go +++ b/internal/ini/walker_test.go @@ -24,6 +24,9 @@ func TestDataFiles(t *testing.T) { { path: "./testdata/valid/simple_profile", }, + { + path: "./testdata/valid/arn_profile", + }, { path: "./testdata/valid/commented_profile", },