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: convert non-latin characters in IE #157

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/util/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const uintToString = (uintArray) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but this function is doing a bit more than just converting the typed array to a string. We may want to either rename the function or just call decodeURIComponent and escape within vtt-segment-loader.

decodeURIComponent(escape(String.fromCharCode.apply(null, uintArray)));
5 changes: 1 addition & 4 deletions src/vtt-segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import videojs from 'video.js';
import window from 'global/window';
import { removeCuesFromTrack } from './mse/remove-cues-from-track';
import { initSegmentId } from './bin-utils';
import { uintToString } from './util/string';

const VTT_LINE_TERMINATORS =
new Uint8Array('\n\n'.split('').map(char => char.charCodeAt(0)));

const uintToString = function(uintArray) {
return String.fromCharCode.apply(null, uintArray);
};

/**
* An object that manages segment loading and appending.
*
Expand Down
10 changes: 10 additions & 0 deletions test/util/string.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import QUnit from 'qunit';
import { uintToString } from '../../src/util/string';

QUnit.module('uintToString');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but may want a blank line here

QUnit.test('converts beyond Latin-1 characters', function(assert) {
const expected = 'シ';
const actual = uintToString(new Uint8Array([227, 130, 183]));

assert.deepEqual(actual, expected);
});