Opened 11 months ago

Closed 11 months ago

Last modified 9 months ago

#23333 closed Bug (fixed)

urlsafe_base64_encode/decode don't round-trip on python3

Reported by: Ian-Foote Owned by: Ian-Foote
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The functions urlsafe_base64_encode and urlsafe_base64_decode in django.utils.http should be inverses of each other, but on python3 urlsafe_base64_encode returns bytes but urlsafe_base64_decode expects a str. I've created a test for this on a github branch.

Change History (8)

comment:1 Changed 11 months ago by claudep

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Confirmed. The solution is probably to use django.utils.encoding.force_bytes instead of calling encode directly.

comment:2 Changed 11 months ago by Ian-Foote

I've updated my branch with your suggested fix and created a pull request.

comment:3 Changed 11 months ago by Ian-Foote

  • Has patch set
  • Owner changed from nobody to Ian-Foote
  • Status changed from new to assigned

comment:4 Changed 11 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 03d89168a27f7c5a8fb4b466170c997aca5fdf02:

Fixed #23333 -- Made urlsafe_base64_decode() return proper type on Python 3.

comment:5 Changed 9 months ago by Ian-Foote

Can this fix be backported to 1.6 and 1.7?

comment:6 Changed 9 months ago by timgraham

As a bug in a new feature in 1.6, yes. However, after the release of 1.7, 1.6 is only receiving security fixes so I think we should do 1.7 only.

comment:7 Changed 9 months ago by Tim Graham <timograham@…>

In d8306650071369ee9d7cad71120d13c22e900a10:

[1.7.x] Fixed #23333 -- Made urlsafe_base64_decode() return proper type on Python 3.

Backport of 03d89168a2 from master

comment:8 Changed 9 months ago by Tim Graham <timograham@…>

In 9e2e4cb6dda5fa1d4d6b047adbcc215daf4d6ff1:

Added 1.7.1 release notes for refs #23333.

Note: See TracTickets for help on using tickets.
Back to Top