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

Adjust regex to handle square brackets #774

Merged
merged 3 commits into from
Jun 6, 2024
Merged

Conversation

zoeyTM
Copy link
Contributor

@zoeyTM zoeyTM commented Jun 4, 2024

fixes #762

Adjusted the regex to be more strict in general as there were some invalid cases that were being allowed with the previous regex (even though they would be caught later in the validation process).

Added tests for relevant passing and failing cases

--

I also verified manually that square brackets are allowed in filenames in both unix and windows systems, so that is a non-issue.

@zoeyTM zoeyTM requested a review from kanej June 4, 2024 04:51
*/
const functionNameRegex = /^[a-zA-Z$_][a-zA-Z0-9$_,()]*$/;
const functionNameRegex = /^[a-zA-Z0-9$_]*(\([a-zA-Z0-9$_,\[\]]*\))?$/;
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch.
Are there any backwards compatibility concerns here?

Copy link
Member

Choose a reason for hiding this comment

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

Should the * be a +?
Would the following incorrectly pass (uint256)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the * be a +?

Ah that's a great catch, I just pushed an update to fix that (with a new test case to verify)

Are there any backwards compatibility concerns here?

I don't believe so. The biggest potential impacts I was aware of while writing this were:

  1. The rightmost * needs to stay an * and not be changed to a +. This change would break myFunc() which currently works
  2. Due to how the regex was previously written, 0-9 was allowed to be in the function name, which looks unintentional, but is actually correct as that is valid solidity. I added 0-9 to the first character set to continue this behavior.

I believe these are the only two potential breaking changes of things that should work before and after the change. This technically has a breaking change in that new invalid patterns will fail, but they would have failed later in the code anyways previously, so I don't believe this is actually a breaking change. They just properly throw where intended now.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I follow now. The move is all about reworking the parameter list.
We support [] in the parameter list and this is allows additional valid identifiers, so no breaking change there - agreed.
I sharpened up the first part in firstpart(secondparts[]), so that the first character can't be a number: https://docs.soliditylang.org/en/v0.8.26/grammar.html#a4.SolidityLexer.Identifier.
It could be argued that we could sharpen up the parameter list as well, but I am happy with the current level of precision. What do you think?

Copy link
Member

@kanej kanej left a comment

Choose a reason for hiding this comment

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

I left a few comments, but this looks good.

zoeyTM and others added 2 commits June 5, 2024 10:54
The Solidity grammar suggests that the first character of an identifier must be
a letter.

It is arguable therefore, that we should do that for the args list, but I think
this increment in precision is enough.

See https://docs.soliditylang.org/en/v0.8.26/grammar.html#a4.SolidityLexer.Identifier
Copy link
Member

@kanej kanej left a comment

Choose a reason for hiding this comment

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

LGTM!

@zoeyTM zoeyTM merged commit 5aa369f into development Jun 6, 2024
5 checks passed
@zoeyTM zoeyTM deleted the fix/overload-brackets branch June 6, 2024 14:43
@zoeyTM zoeyTM mentioned this pull request Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Throwing error when calling overloaded functions in Hardhat-Ignition module.
2 participants