Skip to content

Commit

Permalink
Additional Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Jul 1, 2021
1 parent 55844bb commit 97efa36
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### SDK Features
* `internal/ini`: The ini parser has been updated to support `[`, `]`, `:`, and `=` being present in section key values. ([#3958](https://github.com/aws/aws-sdk-go/issues/3958))

### SDK Enhancements

Expand Down
33 changes: 23 additions & 10 deletions internal/ini/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,30 @@
// }
//
// Below is the BNF that describes this parser
// Grammar:
// stmt -> value stmt'
// stmt' -> epsilon | op stmt
// value -> number | string | boolean | quoted_string
// Grammar:
// stmt -> section | stmt'
// stmt' -> epsilon | expr
// expr -> value (stmt)* | equal_expr (stmt)*
// equal_expr -> value ( ':' | '=' ) equal_expr'
// equal_expr' -> number | string | quoted_string
// quoted_string -> " quoted_string'
// quoted_string' -> string quoted_string_end
// quoted_string_end -> "
//
// section -> [ section'
// section' -> value section_close
// section_close -> ]
// section -> [ section'
// section' -> section_value section_close
// section_value -> number | string_subset | boolean | quoted_string_subset
// quoted_string_subset -> " quoted_string_subset'
// quoted_string_subset' -> string_subset quoted_string_end
// quoted_string_subset -> "
// section_close -> ]
//
// SkipState will skip (NL WS)+
// value -> number | string_subset | boolean
// string -> ? UTF-8 Code-Points except '\n' (U+000A) and '\r\n' (U+000D U+000A) ?
// string_subset -> ? Code-points excepted by <string> grammar except ':' (U+003A), '=' (U+003D), '[' (U+005B), and ']' (U+005D) ?
//
// comment -> # comment' | ; comment'
// comment' -> epsilon | value
// SkipState will skip (NL WS)+
//
// comment -> # comment' | ; comment'
// comment' -> epsilon | value
package ini
12 changes: 0 additions & 12 deletions internal/ini/ini_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,6 @@ loop:
case ValueState:
// ValueState requires the previous state to either be an equal expression
// or an expression statement.
//
// This grammar occurs when the RHS is a number, word, or quoted string.
// equal_expr -> lit op equal_expr'
// equal_expr' -> number | string | quoted_string
// quoted_string -> " quoted_string'
// quoted_string' -> string quoted_string_end
// quoted_string_end -> "
//
// otherwise
// expr_stmt -> equal_expr (expr_stmt')*
// expr_stmt' -> ws S | op S | MarkComplete
// S -> equal_expr' expr_stmt'
switch k.Kind {
case ASTKindEqualExpr:
// assigning a value to some key
Expand Down
1 change: 1 addition & 0 deletions internal/ini/testdata/invalid/bad_section_name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ :=foo ]
1 change: 1 addition & 0 deletions internal/ini/testdata/invalid/bad_syntax_2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ foo ]]
2 changes: 2 additions & 0 deletions internal/ini/testdata/invalid/invalid_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[assumerole]
key[id] = value
32 changes: 28 additions & 4 deletions internal/ini/testdata/valid/op_sep_in_values
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
[default]
[case1]
sepInValue = =:[foo]]bar[
output = json
[assumerole]
key:= value1

[case2]
sepInValue==:[foo]]bar[
output = json
key = value2

[case3]
sepInValue = []
key== value3

[case4]
sepInValue = [value] x=a
key:=value4

[case5]
key : value5

[case6]
s3 =
[nested6]
key = valuen6
key :=value6

[case7]
s3 =
key :value7
[sub7]
key ==values7
34 changes: 28 additions & 6 deletions internal/ini/testdata/valid/op_sep_in_values_expected
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
{
"default": {
"sepInValue": "=:[foo]]bar[",
"output": "json"
"case1": {
"sepinvalue": "=:[foo]]bar[",
"key": "= value1"
},
"assumerole": {
"sepInValue": "=:[foo]]bar[",
"output": "json"
"case2": {
"sepinvalue": "=:[foo]]bar[",
"key": "value2"
},
"case3": {
"sepinvalue": "[]",
"key": "= value3"
},
"case4": {
"sepinvalue": "[value] x=a",
"key": "=value4"
},
"case5": {
"key": "value5"
},
"case6": {
"s3": "",
"key": "=value6"
},
"case7": {
"s3": "",
"key": "value7"
},
"sub7": {
"key": "=values7"
}
}
3 changes: 3 additions & 0 deletions internal/ini/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (v *DefaultVisitor) VisitExpr(expr AST) error {

rhs := children[1]

// The right-hand value side the equality expression is allowed to contain '[', ']', ':', '=' in the values.
// If the token is not either a literal or one of the token types that identifies those four additional
// tokens then error.
if !(rhs.Root.Type() == TokenLit || rhs.Root.Type() == TokenOp || rhs.Root.Type() == TokenSep) {
return NewParseError("unexpected token type")
}
Expand Down
8 changes: 8 additions & 0 deletions internal/ini/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func TestInvalidDataFiles(t *testing.T) {
path: "./testdata/invalid/bad_syntax_1",
expectedParseError: true,
},
{
path: "./testdata/invalid/bad_syntax_2",
expectedParseError: true,
},
{
path: "./testdata/invalid/incomplete_section_profile",
expectedParseError: true,
Expand All @@ -113,6 +117,10 @@ func TestInvalidDataFiles(t *testing.T) {
path: "./testdata/invalid/syntax_error_comment",
expectedParseError: true,
},
{
path: "./testdata/invalid/invalid_keys",
expectedParseError: true,
},
}

for i, c := range cases {
Expand Down

0 comments on commit 97efa36

Please sign in to comment.