-
Notifications
You must be signed in to change notification settings - Fork 26
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { assert } from "chai"; | ||
|
||
import { isValidFunctionOrEventName } from "../../src/internal/utils/identifier-validators"; | ||
|
||
describe("isValidFunctionOrEventName", () => { | ||
it("should return true for valid solidity function names", () => { | ||
assert.isTrue(isValidFunctionOrEventName("myFunction")); | ||
assert.isTrue(isValidFunctionOrEventName("myFunction()")); | ||
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256)")); | ||
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256)")); | ||
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256,bool)")); | ||
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256[],bool)")); | ||
}); | ||
|
||
it("should return false for invalid solidity function names", () => { | ||
assert.isFalse(isValidFunctionOrEventName("myFunction(")); | ||
assert.isFalse(isValidFunctionOrEventName("myFunction(uint)256")); | ||
assert.isFalse(isValidFunctionOrEventName("myFunction(uint256")); | ||
assert.isFalse(isValidFunctionOrEventName("myFunctionuint256)")); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a great catch, I just pushed an update to fix that (with a new test case to verify)
I don't believe so. The biggest potential impacts I was aware of while writing this were:
*
needs to stay an*
and not be changed to a+
. This change would breakmyFunc()
which currently works0-9
was allowed to be in the function name, which looks unintentional, but is actually correct as that is valid solidity. I added0-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.
There was a problem hiding this comment.
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?