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

asBase64Decoded does not work with URL-safe base64 string #3069

Open
amuraco opened this issue Jun 6, 2023 · 5 comments · May be fixed by #3475
Open

asBase64Decoded does not work with URL-safe base64 string #3069

amuraco opened this issue Jun 6, 2023 · 5 comments · May be fixed by #3475
Assignees
Labels
status: ideal for contribution An issue that a contributor can help us with

Comments

@amuraco
Copy link

amuraco commented Jun 6, 2023

Describe the bug
Certain Strings containing "~" when base64 ended end up with a "+" in the output base64, however this is not ideal when used in URLs, so there's a specific variant of Base64 that is URL safe, which results in a "-" in the output instead. The JDK includes Base64.getUrlEncoder() / Base64.getUrlDecoder() for this usecase.

When using AssertJ's asBase64Decoded, it fails since it's not allowing the URL safe variant.

  • assertj core version: 3.24.1
  • java version: 11, 19
  • test framework version: junit 5

Test case reproducing the bug

String base64data = Base64.getUrlEncoder().encodeToString("fo~o".getBytes());
assertThat(base64data).asBase64Decoded().asString().isEqualTo("fo~o");

Expected: Assertion pass
Actual:
java.lang.AssertionError:
Expecting "Zm9-bw==" to be a valid Base64 encoded string

@amuraco amuraco changed the title Base64 function on string do not work with URL-encoded base64 string asBase64Decoded does not work with URL-encoded base64 string Jun 6, 2023
@amuraco amuraco changed the title asBase64Decoded does not work with URL-encoded base64 string asBase64Decoded does not work with URL-safe base64 string Jun 6, 2023
@scordio
Copy link
Member

scordio commented Jun 6, 2023

Being the URL encoding different from the basic one, what if we would add URL-specific methods?

  • isBase64Url
  • asBase64UrlDecoded
  • asBase64UrlEncoded

@scordio scordio added the status: waiting for feedback We need additional information before we can continue label Jun 6, 2023
@bjansen
Copy link

bjansen commented May 7, 2024

@scordio I like your suggestion.

@scordio scordio added status: ideal for contribution An issue that a contributor can help us with and removed status: waiting for feedback We need additional information before we can continue labels May 7, 2024
@scordio
Copy link
Member

scordio commented May 7, 2024

Thanks @bjansen for your feedback 🙂 I marked this issue as ideal for contribution.

@bjansen
Copy link

bjansen commented May 7, 2024

OK, I'll try opening a PR then.

@scordio
Copy link
Member

scordio commented May 7, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal for contribution An issue that a contributor can help us with
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants