Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws if path token starts with underscore #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions db/conditionParser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions db/conditionParser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ PathExpression
_ '[' _ ix:[0-9]+ _ ']' {
return +(ix.join(''))
}
/ _ '.' _ prop:Identifier {
/ _ '.' _ prop:PathIdentifier {
return prop
}
)* {
return (Array.isArray(head) ? head : [head]).concat(tail)
}

GroupedPathExpression
= Identifier
= PathIdentifier
/ '(' _ '(' _ path:PathExpression _ ')' _ ')' {
redundantParensError()
return path
Expand All @@ -366,10 +366,19 @@ Identifier
}
/ ExpressionAttributeName

PathIdentifier
= !ReservedWord head:PathIdentifierStart tail:IdentifierPart* {
return head + tail.join('')
}
/ ExpressionAttributeName

IdentifierStart
= [a-zA-Z]
/ '_'

PathIdentifierStart
= [a-zA-Z]

IdentifierPart
= IdentifierStart
/ [0-9]
Expand Down
12 changes: 12 additions & 0 deletions test/putItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,18 @@ describe('putItem', function() {
helpers.deleteWhenActive(table.TableName)
})
})

it('should return ValidationException if path token starts with underscore', function(done) {
async.forEach([
{ ConditionExpression: 'attribute_not_exists(_c)' },
{ ConditionExpression: 'attribute_not_exists(c._d)'},
], function(putData, cb) {
putData.TableName = helpers.testRangeTable
putData.Item = {a: {S: 'a'}, b: {S: 'b'}}
assertValidation(putData, /^Invalid ConditionExpression: Syntax error;/, cb)
}, done)
})

})

// A number can have up to 38 digits precision and can be between 10^-128 to 10^+126
Expand Down