Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove base64 padding #12

Merged
merged 2 commits into from
May 25, 2017
Merged

Remove base64 padding #12

merged 2 commits into from
May 25, 2017

Conversation

alloy
Copy link
Contributor

@alloy alloy commented May 25, 2017

Consider the following example:

$ curl -Is http://link.artsy.net/click/9692723.214027/aHR0cHM6Ly93d3cuYXJ0c3kubmV0L3ZlbmljZS1iaWVubmFsZS9zdHVkaW8tdmVuZXppYT91dG1fc291cmNlPXNhaWx0aHJ1JnV0bV9tZWRpdW09ZW1haWwmdXRtX2NhbXBhaWduPTk2OTI3MjMtMDUtMjUtMTctRWRpdG9yaWFsJnV0bV90ZXJtPUFydHN5RmVhdHVyZWRTdG9yaWVz/56d8ca89e9a8a2c4168b4f56Cfbb99b59 | grep Location

Location: https://www.artsy.net/venice-biennale/studio-venezia?utm_source=sailthru&utm_medium=email&utm_campaign=9692723-05-25-17-Editorial&utm_term=ArtsyFeaturedStories

The encoded pattern we have for this is L3ZlbmljZS1iaWVubmFsZQ==, which is not present in the encoded URL. That’s because Base64 encodes in chunks of 3 input bytes and pads the remainder, which means that if the unencoded pattern isn’t exactly a multiple of 3 characters long:

  • the trailing = signs will be included, which will not be present in the encoded URL
  • the last characters get encoded with the characters following

So instead of encoding /venice-biennale as L3ZlbmljZS1iaWVubmFsZQ==, or even L3ZlbmljZS1iaWVubmFsZQ, we only encode /venice-biennale to L3ZlbmljZS1iaWVubmFs which is present in the encoded URL.

@kanaabe
Copy link
Contributor

kanaabe commented May 25, 2017

Gotcha. Thanks for the explanation and PR. I'll merge and deploy the related apps.

@kanaabe kanaabe merged commit 47bd1ac into master May 25, 2017
@icirellik icirellik deleted the remove-base64-padding branch December 7, 2020 21:46
@artsyit
Copy link
Contributor

artsyit commented Nov 2, 2021

🚀 PR was released in v1.1.0 🚀

@artsyit artsyit added the released This issue/pull request has been released. label Nov 2, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants