Skip to content

Commit

Permalink
Throws if path token starts with underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Aug 24, 2021
1 parent 58d0955 commit e64526f
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
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

0 comments on commit e64526f

Please sign in to comment.