Skip to content

Base.encode64 and url_encode64 do not accept :case as a valid option#14

Open
agatheblues wants to merge 1 commit intopatricksrobertson:masterfrom
agatheblues:master
Open

Base.encode64 and url_encode64 do not accept :case as a valid option#14
agatheblues wants to merge 1 commit intopatricksrobertson:masterfrom
agatheblues:master

Conversation

@agatheblues
Copy link

Hello!

This PR results from an error raised by Dialyzer, when using SecureRandom.base64() or SecureRandom.urlsafe_base64() in a function foo/0:

Function foo/0 has no local return.

While digging further, it turns out that Dialyzer raises because Base.encode64() and Base.url_encode64() do not support a :case option:

The function call will not succeed.

Base.encode64(binary(), [{:case, :lower}])

breaks the contract
(binary(), [{:padding, boolean()}]) :: binary()

See the recent elixir docs: https://hexdocs.pm/elixir/Base.html#url_encode64/2 & https://hexdocs.pm/elixir/Base.html#encode64/2.

I'm not sure if the option ever made sense (or why Dialyzer didn't raise this ealier in my project 🤷‍♀️) - but I hope the PR will at least help other peeps running into this issue, as the original Dialyzer error is cryptic 🥸.

@dingosky
Copy link

dingosky commented Sep 1, 2025

FWIW, you should NOT use SecureRandom.url_encode64/1 without the change noted in issue #13 by @cheerfulstoic.

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.

2 participants