GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use urlsafe variant of base64 · Issue #463 · googleapis/google-cloud-node

Use urlsafe variant of base64 #463

New issue
Copy link
New issue
Copy link
Closed
Closed
Use urlsafe variant of base64#463
Copy link
Assignees
tmatsuo
Labels
🚨This issue needs some love.coretriage meI really want to be triaged.

Description

@tmatsuo
tmatsuo
opened on Mar 25, 2015
Issue body actions

For a historical reason, all the other samples and client libraries are using the url safe variant of base64 encode/decode.

Is it possible to use the url safe variant?

Activity

Next
  1. stephenplusplus commented on Mar 26, 2015

    @stephenplusplus
    stephenplusplus
    on Mar 26, 2015
    Contributor
    More actions

    Definitely, if it's important to do that for the API. Do you have any API documentation that I can look at that advises to use url-safe?

    A quick search turned up https://github.com/RGBboy/urlsafe-base64 if we decide to implement.

  2. stephenplusplus
    added
    core
    on Mar 26, 2015
  3. ryanseys commented on Mar 26, 2015

    @ryanseys
    ryanseys
    on Mar 26, 2015
    Contributor
    More actions

    Some APIs expect base64url (like Task Queues or GMail). The example for pubsub here specifically shows an example using base64 (not url variant) being encoded so that's strange. I'd hope that the url variant would still work. That being said, having a utils#base64urlencode and utils#base64decode used across the library would be great to consolidate this functionality across all libraries, regardless of what variant we use.

  4. tmatsuo commented on Mar 26, 2015

    @tmatsuo
    tmatsuo
    on Mar 26, 2015
    ContributorAuthor
    More actions

    Do you have any API documentation that I can look at that advises to use url-safe?

    It's Python, but the implementation is simple (uses '-' instead of '+' and '_' instead of '/'.):

    def b64encode(s, altchars=None):
        """Encode a string using Base64.
    
        s is the string to encode.  Optional altchars must be a string of at least
        length 2 (additional characters are ignored) which specifies an
        alternative alphabet for the '+' and '/' characters.  This allows an
        application to e.g. generate url or filesystem safe Base64 strings.
    
        The encoded string is returned.
        """
        # Strip off the trailing newline
        encoded = binascii.b2a_base64(s)[:-1]
        if altchars is not None:
            return _translate(encoded, {'+': altchars[0], '/': altchars[1]})
        return encoded
    
    def urlsafe_b64encode(s):
        """Encode a string using a url-safe Base64 alphabet.
    
        s is the string to encode.  The encoded string is returned.  The alphabet
        uses '-' instead of '+' and '_' instead of '/'.
        """
        return b64encode(s, '-_')

    The example for pubsub here specifically shows an example using base64 (not url variant) being encoded so that's strange.

    Which part is showing it?

    Java library (pubsubMessage.encodeData) uses the urlsafe variant under the cover, Python uses base64.urlsafe_b64encode.

  5. ryanseys commented on Mar 26, 2015

    @ryanseys
    ryanseys
    on Mar 26, 2015
    Contributor
    More actions

    The = are removed in the url variant as well

  6. ryanseys commented on Mar 26, 2015

    @ryanseys
    ryanseys
    on Mar 26, 2015
    Contributor
    More actions

    so the data field of the example has = leading me to believe it's not the url variant

  7. tmatsuo commented on Mar 26, 2015

    @tmatsuo
    tmatsuo
    on Mar 26, 2015
    ContributorAuthor
    More actions

    Aha, I found there is a discrepancy between the Java implementation and the Python implementation.

    Only the Python implementation adds the padding at the end, and I used the value from the Python's base64.urlsafe_b64encode for that protocol example.

    Then I would say, yes, please use the one that @stephenplusplus mentioned.

  8. ryanseys commented on Mar 26, 2015

    @ryanseys
    ryanseys
    on Mar 26, 2015
    Contributor
    More actions

    Oh! it's padding, cool! I didn't know that. :)

  9. tmatsuo commented on Apr 22, 2015

    @tmatsuo
    tmatsuo
    on Apr 22, 2015
    ContributorAuthor
    More actions

    It turned out that, we should just use the standard Base64 variant, so I'm just going to close this bug. I'm very sorry if you've already worked on this. Please ask me for more details if you're interested in.

  10. tmatsuo
    closed this as completedon Apr 22, 2015
  11. stephenplusplus commented on Apr 22, 2015

    @stephenplusplus
    stephenplusplus
    on Apr 22, 2015
    Contributor
    More actions

    No problem, thanks for the update!

  12. yoshi-automation
    added
    🚨This issue needs some love.
    triage meI really want to be triaged.
    on Apr 6, 2020
  13. JustinBeckwith
    assigned
    tmatsuo
    on Feb 1, 2021
  14. chingor13
    added a commit that references this issue on Aug 22, 2022

    chore(deps): update dependency sinon to v10 (#463)

    08219e4
  15. 27 remaining items

  16. GautamSharda
    added 2 commits that reference this issue on Feb 3, 2026

    fix: correct a typo in a code comment (#463)

    a3845fe

    fix: apache license URL (#468) (#463)

    2520bef
  17. GautamSharda
    added a commit that references this issue on Feb 23, 2026

    fix: apache license URL (#468) (#463)

    a99b5b8
  18. sofisl
    added a commit that references this issue on Feb 25, 2026

    chore: add types to many unit tests (#463)

    b16b6d0
  19. GautamSharda
    added 2 commits that reference this issue on Feb 25, 2026

    chore: [node] add auto-approve templates, and install dependencies wi…

    b445053

    fix: apache license URL (#468) (#463)

    5400ae1
  20. GautamSharda
    added a commit that references this issue on Mar 5, 2026

    chore(deps): update dependency eslint-plugin-node to v9 (#463)

    3d17af2
  21. sofisl
    added a commit that references this issue on Mar 5, 2026

    chore(main): release 4.0.0 (#463)

    d23be62
  22. GautamSharda
    added 2 commits that reference this issue on Mar 11, 2026

    test: update code style of smoke test (#463)

    778b32f

    chore: updated eslint and prettier configs (#561)

    6533813
  23. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    chore: add types to many unit tests (googleapis#463)

    7f5c6bd
  24. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    build!: upgrade engines field to >=8.10.0 (#463)

    5c9f83a

    build!: upgrade engines field to >=8.10.0 (#463)

    e87f929
  25. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    build!: upgrade engines field to >=8.10.0 (#463)

    2dc4fa1
  26. thiyaguk09
    added a commit that references this issue on May 5, 2026

    build!: upgrade engines field to >=8.10.0 (googleapis#463)

    2610fb9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tmatsuo
    tmatsuo

Labels

🚨This issue needs some love.coretriage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.