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 isBase64 string property #743

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add isBase64 string property #743

wants to merge 1 commit into from

Conversation

jjuliano
Copy link

This PR adds isBase64 string property.

@StefMa
Copy link
Contributor

StefMa commented Oct 27, 2024

If we add this, do we need this for the other hash functions as well? Sha, md5 etc? 🤔

@jjuliano
Copy link
Author

jjuliano commented Oct 27, 2024

If we add this, do we need this for the other hash functions as well? Sha, md5 etc? 🤔

Maybe it makes sense only for base64 due to the base64Decoded string property. Another approach is to make base64Decoded detect if a string is a base64 through str?.base64Decoded.

@bioball
Copy link
Contributor

bioball commented Oct 28, 2024

What's the use-case for this? Is it for defining a constraint?

Today, you can do this in-language:

function isBase64(str: String) = str.match(Regex("[-A-Za-z0-9+/]*={0,3}"))

Or, a more precise version, and also a little bit more expensive:

import "pkl:test"

function isBase64(str: String) = test.catchOrNull(() -> str.base64Decoded) == null

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.

3 participants