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 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
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 uint8ToUtf8 = (uintArray) =>
decodeURIComponent(escape(String.fromCharCode.apply(null, uintArray)));
9 changes: 3 additions & 6 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 { uint8ToUtf8 } 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 Expand Up @@ -334,7 +331,7 @@ export default class VTTSegmentLoader extends SegmentLoader {
let mapData = segmentInfo.segment.map.bytes;

if (decodeBytesToString) {
mapData = uintToString(mapData);
mapData = uint8ToUtf8(mapData);
}

parser.parse(mapData);
Expand All @@ -343,7 +340,7 @@ export default class VTTSegmentLoader extends SegmentLoader {
let segmentData = segmentInfo.bytes;

if (decodeBytesToString) {
segmentData = uintToString(segmentData);
segmentData = uint8ToUtf8(segmentData);
}

parser.parse(segmentData);
Expand Down
11 changes: 11 additions & 0 deletions test/util/string.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import QUnit from 'qunit';
import { uint8ToUtf8 } from '../../src/util/string';

QUnit.module('uint8ToUtf8');

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

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