Skip to main content

is_base64_value

Function is_base64_value 

Source
pub fn is_base64_value(s: &str) -> bool
Expand description

The inverse. Rejects any character outside the alphabet rather than skipping it, because a lenient decoder would silently accept a corrupted payload from an untrusted client. Does this string match BytesCoder.base64Pattern?

^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$

Written out rather than pulled in as a regex because the shape is simple and the rule is exact: the total length is always a multiple of four, since the optional trailing group is four characters either way, and padding may only be the final one or two characters. The empty string matches, which upstream’s pattern also allows.

This decides whether a plain string stored in a Bytes column is a legacy Bytes value. isValidDatabaseObject is object instanceof mongodb.Binary || this.isBase64Value(object), so a column written by an older parse-server holds the string form and still has to raise to the envelope.