SchemaJSRenderer renders invalid Javascript by steffann · Pull Request #5607 · encode/django-rest-framework (original) (raw)

Under Py3 the base64.b64encode() method returns a binary object, which gets rendered as b'...' in schema.js. This results in the output becoming:

var coreJSON = window.atob('b'eyJf...'');

which is invalid Javascript. Because base64 only uses ASCII characters it is safe to decode('ascii') it. Under Py2 this will result in a unicode object, which is fine. Under Py3 it results in a string, which is also fine. This solves the problem and results in a working schema.js output.

refs #5608