Skip to content

Commit 3db3b14

Browse files
authored
Fix edge cases when parsing subproperties (#2359)
1 parent 5aa6e2b commit 3db3b14

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "d767f490-a7f6-44eb-b9eb-36f126053870",
3+
"type": "feature",
4+
"description": "BREAKFIX: In order to support subproperty parsing, invalid property definitions must not be ignored",
5+
"modules": [
6+
"internal/ini",
7+
"config"
8+
]
9+
}

config/shared_config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var (
2525
testConfigFilename = filepath.Join("testdata", "shared_config")
2626
testConfigOtherFilename = filepath.Join("testdata", "shared_config_other")
2727
testCredentialsFilename = filepath.Join("testdata", "shared_credentials")
28+
testConfigLeadingWSFilename1 = filepath.Join("testdata", "leading_ws")
29+
testConfigLeadingWSFilename2 = filepath.Join("testdata", "leading_ws_trailing_nl")
2830
)
2931

3032
func TestNewSharedConfig(t *testing.T) {
@@ -685,6 +687,16 @@ func TestNewSharedConfig(t *testing.T) {
685687
EC2IMDSv1Disabled: aws.Bool(false),
686688
},
687689
},
690+
"leading whitespace error 1": {
691+
ConfigFilenames: []string{testConfigLeadingWSFilename1},
692+
Profile: "leading-whitespace-error",
693+
Err: fmt.Errorf("Invalid token, remove leading whitespace"),
694+
},
695+
"leading whitespace error 2": {
696+
ConfigFilenames: []string{testConfigLeadingWSFilename2},
697+
Profile: "leading-whitespace-error",
698+
Err: fmt.Errorf("Invalid token, remove leading whitespace"),
699+
},
688700
}
689701

690702
for name, c := range cases {

config/testdata/leading_ws

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[profile leading-whitespace-error]
2+
retry_mode = standard
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[profile leading-whitespace-error]
2+
retry_mode = standard
3+

internal/ini/ini_parser.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ loop:
187187
stack.Push(k)
188188
case StatementState:
189189
if k.Kind != ASTKindStart {
190+
if tok.Type() == TokenLit && isSubProperty(tok.raw) {
191+
return nil, NewParseError(
192+
fmt.Sprintf(
193+
"Invalid token, remove leading whitespace %s",
194+
string(tok.raw)),
195+
)
196+
}
190197
stack.MarkComplete(k)
191198
}
192199
expr := newExpression(tok)

internal/ini/literal_tokens.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func getSubProperty(runes []rune, offset int) (int, error) {
178178
return offset + idx, nil
179179
}
180180
}
181-
return 0, fmt.Errorf("no sub property")
181+
return offset + len(runes), nil
182182
}
183183

184184
// MapValue returns a map value for sub properties

0 commit comments

Comments
 (0)