@@ -14,9 +14,9 @@ test('BAD: should throw in strict mode if header is missing', async () => {
14
14
) . rejects . toThrowError ( ) ;
15
15
} ) ;
16
16
17
- test ( 'GOOD: parse header metadata' , async ( ) => {
17
+ test ( 'GOOD: parse header metadata with : and = ' , async ( ) => {
18
18
const { errors, metadata, cues } = await parseText (
19
- [ 'WEBVTT' , 'Kind: Language' , 'Language: en-US' ] . join ( '\n' ) ,
19
+ [ 'WEBVTT' , 'Kind: Language' , 'Language= en-US' ] . join ( '\n' ) ,
20
20
) ;
21
21
22
22
expect ( errors ) . toHaveLength ( 0 ) ;
@@ -29,3 +29,49 @@ test('GOOD: parse header metadata', async () => {
29
29
}
30
30
` ) ;
31
31
} ) ;
32
+
33
+ test ( 'GOOD: parse header metadata with proper trimming' , async ( ) => {
34
+ const { errors, metadata, cues } = await parseText (
35
+ [ 'WEBVTT' , 'Message:Hello World! ' , ' My Property : Value ' ] . join ( '\n' ) ,
36
+ ) ;
37
+
38
+ expect ( errors ) . toHaveLength ( 0 ) ;
39
+ expect ( cues ) . toHaveLength ( 0 ) ;
40
+
41
+ expect ( metadata ) . toStrictEqual ( {
42
+ 'Message' : 'Hello World!' ,
43
+ 'My Property' : 'Value' ,
44
+ } ) ;
45
+ } ) ;
46
+
47
+ test ( 'GOOD: parse header metadata with value containing = or :' , async ( ) => {
48
+ const { errors, metadata, cues } = await parseText (
49
+ [ 'WEBVTT' , 'Key1: Value with = sign' , 'Key2: Value with : colon' ] . join ( '\n' ) ,
50
+ ) ;
51
+
52
+ expect ( errors ) . toHaveLength ( 0 ) ;
53
+ expect ( cues ) . toHaveLength ( 0 ) ;
54
+
55
+ expect ( metadata ) . toStrictEqual ( {
56
+ "Key1" : "Value with = sign" ,
57
+ "Key2" : "Value with : colon" ,
58
+ } ) ;
59
+ } ) ;
60
+
61
+ test ( 'GOOD: parse header metadata with JSON and "=" in value' , async ( ) => {
62
+ const { errors, metadata, cues } = await parseText (
63
+ [ 'WEBVTT' ,
64
+ 'X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0' ,
65
+ 'Json: {"a": 1, "b": 2}' ,
66
+ 'Eval: 1 + 1 = 2' ] . join ( '\n' ) ,
67
+ ) ;
68
+
69
+ expect ( errors ) . toHaveLength ( 0 ) ;
70
+ expect ( cues ) . toHaveLength ( 0 ) ;
71
+
72
+ expect ( metadata ) . toStrictEqual ( {
73
+ "X-TIMESTAMP-MAP" : "LOCAL:00:00:00.000,MPEGTS:0" ,
74
+ "Json" : '{"a": 1, "b": 2}' ,
75
+ "Eval" : "1 + 1 = 2" ,
76
+ } ) ;
77
+ } ) ;
0 commit comments