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

Add label validation for non printable chars #1650

Merged
merged 2 commits into from
Oct 9, 2023
Merged

Conversation

pinosu
Copy link
Contributor

@pinosu pinosu commented Oct 5, 2023

Resolves #1623

@pinosu pinosu added the backport/v0.4x backport patches to sdk47 release branch label Oct 5, 2023
@pinosu pinosu requested a review from alpe as a code owner October 5, 2023 07:23
@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #1650 (0de4811) into main (3ea8575) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1650      +/-   ##
==========================================
+ Coverage   56.56%   56.62%   +0.05%     
==========================================
  Files          62       62              
  Lines        8194     8200       +6     
==========================================
+ Hits         4635     4643       +8     
+ Misses       3121     3120       -1     
+ Partials      438      437       -1     
Files Coverage Δ
x/wasm/types/validation.go 90.00% <100.00%> (+1.76%) ⬆️

... and 1 file with indirect coverage changes

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Nice start. Please see my comment on the test

return !unicode.IsGraphic(r)
})
if label != labelWithoutNonPrintableChars {
return ErrInvalid.Wrap("label must not have non printable characters")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's avoid double negative ;-)

Suggested change
return ErrInvalid.Wrap("label must not have non printable characters")
return ErrInvalid.Wrap("label must have printable characters only")

x/wasm/types/tx_test.go Show resolved Hide resolved
@pinosu pinosu requested a review from alpe October 6, 2023 14:07
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Good work! 🏌️

@@ -45,6 +46,15 @@ func ValidateLabel(label string) error {
if label != strings.TrimSpace(label) {
return ErrInvalid.Wrap("label must not start/end with whitespaces")
}
labelWithPrintableCharsOnly := strings.Map(func(r rune) rune {
Copy link
Contributor

Choose a reason for hiding this comment

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

very nice use of strings.Map 👍

@pinosu pinosu merged commit 1a22c29 into main Oct 9, 2023
8 checks passed
mergify bot pushed a commit that referenced this pull request Oct 9, 2023
* Add label validation for non printable chars

* Fix printable chars check

(cherry picked from commit 1a22c29)
pinosu added a commit that referenced this pull request Oct 11, 2023
* Add label validation for non printable chars

* Fix printable chars check

(cherry picked from commit 1a22c29)
pinosu added a commit that referenced this pull request Oct 11, 2023
* Add label validation for non printable chars

* Fix printable chars check

(cherry picked from commit 1a22c29)

Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.4x backport patches to sdk47 release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent non printable characters in label
2 participants