Skip to content

Commit

Permalink
Merge pull request #3687 from himdel/fixup3682
Browse files Browse the repository at this point in the history
Fix TextEncoderLite in old browsers
(cherry picked from commit 8897622)

https://bugzilla.redhat.com/show_bug.cgi?id=1562797
  • Loading branch information
mzazrivec authored and simaishi committed Apr 2, 2018
1 parent e6aeca1 commit 8636bd6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/javascript/packs/compat-common.js
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);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"base64-js": "~1.2.3",
"core-js": "~2.4.1",
"rxjs": "~5.3.0",
"text-encoder-lite": "~1.0.1",
"text-encoder-lite": "git://github.com/coolaj86/TextEncoderLite.git#e1e031b",
"ui-select": "0.19.8",
"zone.js": "~0.8.5"
},
Expand Down
17 changes: 17 additions & 0 deletions spec/javascripts/miq_api_spec.js
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);
});
});
1 change: 1 addition & 0 deletions spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ src_files:
- assets/angular-mocks
- __spec__/helpers/fixtures-fix.js
- packs/manageiq-ui-classic/application-common.js
- packs/manageiq-ui-classic/compat-common.js

# stylesheets
#
Expand Down

0 comments on commit 8636bd6

Please sign in to comment.