Skip to content

Commit

Permalink
fix: convert non-latin characters in IE (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
forbesjo authored Jul 17, 2018
1 parent 7ac51ee commit 17678fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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);
});

0 comments on commit 17678fb

Please sign in to comment.