-
Notifications
You must be signed in to change notification settings - Fork 35
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
chore: add back removal regex #591
Conversation
WalkthroughThe Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@@ -326,7 +326,7 @@ func (s *CLITestSuite) TestCLITxGrantAuthorization() { | |||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()), | |||
}, | |||
true, | |||
"invalid decimal coin expression", | |||
"nvalid character in denomination: ", |
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.
The error message has been modified to be more specific, which is beneficial. However, there appears to be a typographical error in the message. It should likely start with "Invalid" instead of "nvalid".
- "nvalid character in denomination: ",
+ "Invalid character in denomination: ",
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
"nvalid character in denomination: ", | |
"Invalid character in denomination: ", |
@@ -130,7 +132,7 @@ func (s *coinTestSuite) TestCustomValidation() { | |||
for i, tc := range cases { | |||
s.Require().Equal(tc.expectPass, tc.coin.IsValid(), "unexpected result for IsValid, tc #%d", i) | |||
} | |||
sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex) | |||
sdk.SetCoinDenomRegex(func() string { return reDnmString }) |
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.
After modifying the coin denomination regex with sdk.SetCoinDenomRegex
, it's a good practice to reset it to its original state at the end of the test to prevent unintended side effects on subsequent tests.
+ defer sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
sdk.SetCoinDenomRegex(func() string { return reDnmString }) | |
sdk.SetCoinDenomRegex(func() string { return reDnmString }) | |
defer sdk.SetCoinDenomRegex(sdk.DefaultCoinDenomRegex) |
// isValidRune checks if a given rune is a valid character for a rune. | ||
// It returns true if the rune is a letter, digit, '/', ':', '.', '_', or '-'. | ||
func isValidRune(r rune) bool { | ||
return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '/' || r == ':' || r == '.' || r == '_' || r == '-' | ||
} | ||
|
||
// MatchDenom checks if the given string is a valid denomination. | ||
// A valid denomination must have a length between 3 and 128 characters, | ||
// start with a letter, and only contain valid runes. | ||
func MatchDenom(s string) bool { | ||
length := len(s) | ||
if length < 3 || length > 128 { | ||
return false | ||
} | ||
|
||
firstRune := rune(s[0]) | ||
if !unicode.IsLetter(firstRune) { | ||
return false | ||
} | ||
|
||
for _, r := range s[1:] { | ||
if !isValidRune(r) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
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.
The introduction of isValidRune
and MatchDenom
functions enhances the validation logic by providing clear, focused checks for denomination validity. This modular approach improves the maintainability and readability of the code. It's recommended to add unit tests for these functions to ensure their correctness and handle edge cases effectively.
Would you like me to help with adding unit tests for these new validation functions?
* Reapply "Backport: Removal of regex usage on denom validation (#570)" This reverts commit a07f5de. * changelog (cherry picked from commit 0732c8a) Co-authored-by: Adam Tucker <[email protected]>
Description
Closes: #XXXX
Matt tested and determined this PR is non problematic. Adding it back.
Summary by CodeRabbit
CacheKV
.