File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export const uint8ToUtf8 = ( uintArray ) =>
2+ decodeURIComponent ( escape ( String . fromCharCode . apply ( null , uintArray ) ) ) ;
Original file line number Diff line number Diff line change @@ -6,14 +6,11 @@ import videojs from 'video.js';
66import window from 'global/window' ;
77import { removeCuesFromTrack } from './mse/remove-cues-from-track' ;
88import { initSegmentId } from './bin-utils' ;
9+ import { uint8ToUtf8 } from './util/string' ;
910
1011const VTT_LINE_TERMINATORS =
1112 new Uint8Array ( '\n\n' . split ( '' ) . map ( char => char . charCodeAt ( 0 ) ) ) ;
1213
13- const uintToString = function ( uintArray ) {
14- return String . fromCharCode . apply ( null , uintArray ) ;
15- } ;
16-
1714/**
1815 * An object that manages segment loading and appending.
1916 *
@@ -334,7 +331,7 @@ export default class VTTSegmentLoader extends SegmentLoader {
334331 let mapData = segmentInfo . segment . map . bytes ;
335332
336333 if ( decodeBytesToString ) {
337- mapData = uintToString ( mapData ) ;
334+ mapData = uint8ToUtf8 ( mapData ) ;
338335 }
339336
340337 parser . parse ( mapData ) ;
@@ -343,7 +340,7 @@ export default class VTTSegmentLoader extends SegmentLoader {
343340 let segmentData = segmentInfo . bytes ;
344341
345342 if ( decodeBytesToString ) {
346- segmentData = uintToString ( segmentData ) ;
343+ segmentData = uint8ToUtf8 ( segmentData ) ;
347344 }
348345
349346 parser . parse ( segmentData ) ;
Original file line number Diff line number Diff line change 1+ import QUnit from 'qunit' ;
2+ import { uint8ToUtf8 } from '../../src/util/string' ;
3+
4+ QUnit . module ( 'uint8ToUtf8' ) ;
5+
6+ QUnit . test ( 'converts beyond Latin-1 characters' , function ( assert ) {
7+ const expected = 'シ' ;
8+ const actual = uint8ToUtf8 ( new Uint8Array ( [ 227 , 130 , 183 ] ) ) ;
9+
10+ assert . deepEqual ( actual , expected ) ;
11+ } ) ;
You can’t perform that action at this time.
0 commit comments