DynamoDB: allow leading underscore in expression attr name (#6082)

This commit is contained in:
Bert Blommers 2023-03-17 14:22:05 -01:00 committed by GitHub
parent c4c5cdd3e7
commit 5eef06ee51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -116,8 +116,9 @@ class ExpressionTokenizer(object):
An expression attribute name must begin with a pound sign (#), and be followed by one or more alphanumeric
characters.
"""
return input_string.startswith("#") and cls.is_expression_attribute(
input_string[1:]
return (
input_string.startswith("#")
and re.compile("^[a-zA-Z0-9_]+$").match(input_string[1:]) is not None
)
@classmethod
@ -182,8 +183,9 @@ class ExpressionTokenizer(object):
def _make_list(self) -> List[Token]:
"""
Just go through characters if a character is not a token boundary stage it for adding it as a grouped token
later if it is a tokenboundary process staged characters and then process the token boundary as well.
Just go through characters
if a character is not a token boundary, stage it for adding it as a grouped token later
if it is a tokenboundary, process staged characters, and then process the token boundary as well.
"""
for character in self.input_expression_str:
if not self.is_possible_token_boundary(character):

View File

@ -231,6 +231,18 @@ def test_expression_tokenizer_single_set_action_attribute_name_leading_number():
]
def test_expression_tokenizer_single_set_action_attribute_name_leading_underscore():
set_action = "SET attr=#_sth"
token_list = ExpressionTokenizer.make_list(set_action)
assert token_list == [
Token(Token.ATTRIBUTE, "SET"),
Token(Token.WHITESPACE, " "),
Token(Token.ATTRIBUTE, "attr"),
Token(Token.EQUAL_SIGN, "="),
Token(Token.ATTRIBUTE_NAME, "#_sth"),
]
def test_expression_tokenizer_just_a_pipe():
set_action = "|"
try: