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

Prevent from injecting empty values #41

Merged
merged 2 commits into from
Nov 7, 2019
Merged

Prevent from injecting empty values #41

merged 2 commits into from
Nov 7, 2019

Conversation

ClemDoum
Copy link
Collaborator

Prevent the user to inject empty values. By empty we mean values that contain no characters or only whitespaces.

This was previously allowed and made the injection from vanilla crash when trying to inject after injecting an empty character:

  • when adding the value the first time, the tokenizer used to remove whitespaces from the value couldn't find any token, hence the tokens_symbol_table, token_to_resolved_values and resolved_value_to_tokens where not updated with any token.
  • when injecting a second time, we try to remove the resolved value from the resolved_symbol_table but then when trying to get the tokens of the resolved value with get_tokens_from_resolved_value in order to remove them from the tokens_symbol_table, token_to_resolved_values and resolved_value_to_tokens maps, we can't find any token for the given resolved value since we didn't insert any

@ClemDoum
Copy link
Collaborator Author


if tokens.len() == 0 {
bail!("Can't add value '{}' because it's empty or contains only whitespaces.", entity_value.raw_value)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more efficient to use a boolean flag is_empty and set it to true in the loop. It will avoid creating a vector, and will make injection slightly faster.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another detail is that the resolved_symbol_table should not be updated in case of invalid input.

@adrienball adrienball merged commit 4f29dc9 into master Nov 7, 2019
@adrienball adrienball deleted the fix/empty-values branch November 7, 2019 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants