backporting url-safe_base64.patch from 4.x master

master commit id: 0191ea61fae4875329b6ea0adb55bb6df4dfb195