-
Notifications
You must be signed in to change notification settings - Fork 133
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
Hex validator returns invalid hex string #1790
Comments
Hi @martinboksa and thank you for the report Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow. It seems already got into Now in order to advance to Thank you and sorry that this comment is not a complete solution (yet). |
By the way, it's because the validator parses the hex string into small slices, and then fn |
we're using yarn patch as a (rather simplistic) workaround: diff --git a/cjs/scalars/Byte.js b/cjs/scalars/Byte.js
index e6d3be273a4c77b9e19da28d3cdf3d80d0c75987..beb3936ccd611c92c6bad22c9a3d27daa2d095b7 100644
--- a/cjs/scalars/Byte.js
+++ b/cjs/scalars/Byte.js
@@ -5,18 +5,8 @@ const graphql_1 = require("graphql");
const error_js_1 = require("../error.js");
const base64Validator = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;
function hexValidator(value) {
- // Ensure that any leading 0 is removed from the hex string to avoid false negatives.
- const sanitizedValue = value.charAt(0) === '0' ? value.slice(1) : value;
- // For larger strings, we run into issues with MAX_SAFE_INTEGER, so split the string
- // into smaller pieces to avoid this issue.
- if (value.length > 8) {
- let parsedString = '';
- for (let startIndex = 0, endIndex = 8; startIndex < value.length; startIndex += 8, endIndex += 8) {
- parsedString += parseInt(value.slice(startIndex, endIndex), 16).toString(16);
- }
- return parsedString === sanitizedValue;
- }
- return parseInt(value, 16).toString(16) === sanitizedValue;
+ const regexp = /^[0-9a-fA-F]+$/;
+ return regexp.test(value)
}
function validate(value, ast) {
if (typeof value !== 'string' && !(value instanceof global.Buffer)) { |
Feel free to create a PR for the fix! |
Issue workflow progress
Progress of the issue based on the Contributor Workflow
Describe the bug
I tried to send 'hex' data to graphql server and store them in database (as BYTEA column in postgre) but
hexValidator
always returns an error.IDK why is not working properly, maybe the fix could be to update
hexValidator()
function into regexp.To Reproduce
https://codesandbox.io/p/sandbox/sweet-gianmarco-1bldd6?file=%2Fsrc%2Findex.ts
Environment:
The text was updated successfully, but these errors were encountered: