logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe
commit: bf7b5a7105e6543411d83ba126dab6b00955c98c
parent: f72d6ec83ef753241a9329306c0b3fdf1c3cf534
Author: lambda <pleromagit@rogerbraun.net>
Date:   Tue,  5 Dec 2017 09:13:16 +0000

Merge branch 'fix/unicode-passwords' into 'develop'

Fix basicauth base64 encoding for unicode passwords.

See merge request pleroma/pleroma-fe!180

Diffstat:

Msrc/services/api/api.service.js12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js @@ -43,6 +43,16 @@ let fetch = (url, options) => { return oldfetch(fullUrl, options) } +// from https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding +let utoa = (str) => { + // first we use encodeURIComponent to get percent-encoded UTF-8, + // then we convert the percent encodings into raw bytes which + // can be fed into btoa. + return btoa(encodeURIComponent(str) + .replace(/%([0-9A-F]{2})/g, + (match, p1) => { return String.fromCharCode('0x' + p1) })) +} + // Params // cropH // cropW @@ -156,7 +166,7 @@ const register = (params) => { const authHeaders = (user) => { if (user && user.username && user.password) { - return { 'Authorization': `Basic ${btoa(`${user.username}:${user.password}`)}` } + return { 'Authorization': `Basic ${utoa(`${user.username}:${user.password}`)}` } } else { return { } }