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

fix(ir): Add support for byte format in string validation #1296

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

k4n4ry
Copy link
Contributor

@k4n4ry k4n4ry commented Aug 12, 2024

Fixes #1261

Overview

I've added a new Byte field to the String structure in the validate package.
This field is set to true when format: byte is specified in the string formats of OpenAPI.
When executing character length validation, if the Byte field is true, the length is verified using []byte instead of []rune.

Note

This change may not be necessary.
According to the OpenAPI specification, format: byte is specified for base64-encoded characters.
If the characters used are those in base64 encoding, the length evaluation doesn't change during the []byte -> string -> []rune conversion process.
However, as mentioned in the issue, I suppose this change is necessary if we want to ensure validation behavior for more general bytes fields.

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.93%. Comparing base (12fe015) to head (63919c9).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1296      +/-   ##
==========================================
+ Coverage   73.92%   73.93%   +0.01%     
==========================================
  Files         189      189              
  Lines       12855    12860       +5     
==========================================
+ Hits         9503     9508       +5     
  Misses       2804     2804              
  Partials      548      548              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

length validation of bytes fields incorrectly converts to utf-8 string
1 participant