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

Using '=' for padding does not work for URLs #11

Closed
ochrons opened this issue Feb 26, 2016 · 7 comments
Closed

Using '=' for padding does not work for URLs #11

ochrons opened this issue Feb 26, 2016 · 7 comments

Comments

@ochrons
Copy link

ochrons commented Feb 26, 2016

When coding a query parameter to base64, the padding =s make it invalid. Some other URI compatible character should be used instead.

@marklister
Copy link
Owner

The rfc says

The pad character "=" is typically percent-encoded when used in an
   URI [9], but if the data length is known implicitly, this can be
   avoided by skipping the padding; see section 3.2.

Just thinking out loud here.

@ochrons
Copy link
Author

ochrons commented Feb 26, 2016

Yes, currently I need to run the base64 result through URL escaping to make that happen. But since the code already has special version of b64 for URLs (to avoid escaping), this shoud be part of that feature.

@marklister
Copy link
Owner

Sounds reasonable, so if I pad with %3D that should do the trick? And I guess I should do the same for decoding?

@ochrons
Copy link
Author

ochrons commented Feb 26, 2016

Or since you're not following official base64 encoding anyway, just choose a character that is compatible with URL like .

marklister pushed a commit that referenced this issue Feb 26, 2016
@marklister
Copy link
Owner

I've pushed to master, can you have a look and see what you think?

scala> implicit val e= Base64.base64Url
e: com.github.marklister.base64.Base64.B64Scheme = B64Scheme([C@5b590f33,false,<function1>,<function1>)

scala> "abc".getBytes.toBase64
res0: String = YWJj

scala> "abcd".getBytes.toBase64
res1: String = YWJjZA%3D%3D

scala> res1.toByteArray.map(_.toChar)
res2: Array[Char] = Array(a, b, c, d)

I've tried to follow the RFC as closely as possible. Where have I tripped up?

@ochrons
Copy link
Author

ochrons commented Feb 27, 2016

LGTM

@marklister
Copy link
Owner

v0.2.2 pushed to maven central. Thanks @ochrons for the input!

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

No branches or pull requests

2 participants