Validator.js: isBase64 method wrong validation!

Created on 28 Jan 2020  路  7Comments  路  Source: validatorjs/validator.js

this method [ isBase64 ] is showing incorrect results. In below image.

Capturewewe

馃悰 bug 馃攳needs-investigation

Most helpful comment

@profnandaa The string "1111" is a valid base64 and actually resolves to a string.

All 7 comments

Thanks for reaching raising the issue @KInGATiLLa.
I will do more investigation on the issue here.
Also, other people can do more investigation here.

Why should "1111" not be considered a valid base64 value? Looking at the implementation and the rfc 4648 I can't see why it should be the case.

@profnandaa @ezkemboi i tried to reproduce the issue and that is correct. The string "1111" actually passes the validation which is bizzare. I can do a PR on this shortly if you like

@rubiin -- sure, please do.

@profnandaa The string "1111" is a valid base64 and actually resolves to a string.

The string "" is valid base64 (see first example https://tools.ietf.org/html/rfc4648#section-10) but isBase64("") returns false.

Edit: moved this to a new issue for more visibility as it is clearly a bug.

I agree with @parasg1999. According to section 4 of RFC 4648 (at the bottom of page 5) the following case applies which implies, that 1111 is valid base64 (with each 1 representing 6 bits of the encoded data resulting in 24bits = 3 bytes of data):

(1) The final quantum of encoding input is an integral multiple of 24
bits; here, the final unit of encoded output will be an integral
multiple of 4 characters with no "=" padding.

I suggest closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnandChowdhary picture AnandChowdhary  路  3Comments

MindRapist picture MindRapist  路  4Comments

malkhuzayyim picture malkhuzayyim  路  4Comments

rubiin picture rubiin  路  3Comments

mfbx9da4 picture mfbx9da4  路  4Comments