Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextEncoderLite in old browsers #3687

Merged
merged 2 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,7 +41,7 @@
"react-redux": "^5.0.7",
"redux-devtools-extension": "^2.13.2",
"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 @@ -19,6 +19,7 @@ src_files:
- __spec__/helpers/fixtures-fix.js
- packs/vendor.js
- packs/manageiq-ui-classic/application-common.js
- packs/manageiq-ui-classic/compat-common.js
- packs/manageiq-ui-classic/miq-redux-common.js

# stylesheets
Expand Down