-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3687 from himdel/fixup3682
Fix TextEncoderLite in old browsers (cherry picked from commit 8897622) https://bugzilla.redhat.com/show_bug.cgi?id=1562797
- Loading branch information
Showing
4 changed files
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import base64js from 'base64-js'; | ||
import TextEncoderLite from 'text-encoder-lite'; | ||
const TextEncoderLite = require('text-encoder-lite').TextEncoderLite; | ||
|
||
// utf8-capable window.btoa | ||
window.base64encode = (str, encoding = 'utf-8') => { | ||
let bytes = new (TextEncoder || TextEncoderLite)(encoding).encode(str); | ||
let bytes = new (window.TextEncoder || TextEncoderLite)(encoding).encode(str); | ||
return base64js.fromByteArray(bytes); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
describe('miq_api.js', function() { | ||
it("can base64 encode utf8 passwords", function(done) { | ||
var getArgs; | ||
|
||
spyOn(vanillaJsAPI, 'get').and.callFake(function(_url, args) { | ||
getArgs = args; | ||
return Promise.resolve({}); | ||
}); | ||
|
||
vanillaJsAPI.login('foo', 'páššwøřď 密码 密碼') | ||
.then(function() { | ||
expect(vanillaJsAPI.get).toHaveBeenCalled(); | ||
expect(getArgs.headers.Authorization).toBe("Basic Zm9vOnDDocWhxaF3w7jFmcSPIOWvhueggSDlr4bnorw=") | ||
}) | ||
.then(done, done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters