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

Entities object incorrectly passed to WebVTTCueTextParser #35

Closed
RaminRabani opened this issue Nov 15, 2021 · 0 comments
Closed

Entities object incorrectly passed to WebVTTCueTextParser #35

RaminRabani opened this issue Nov 15, 2021 · 0 comments

Comments

@RaminRabani
Copy link
Contributor

RaminRabani commented Nov 15, 2021

Bug Description

In parser.js, the entities object is assigned to this on line 29:

line 29: this.entities = entities

If we console.log(this) right after line 29, we see that this corresponds to WebVTTParser.

Next on line 30, this.parse is assigned to a function. In the parse function on line 177, it is attempted to pass that same entities object to the WebVTTCueTextParser:

line 177: var cuetextparser = new WebVTTCueTextParser(cue.text, err, mode, this.entities)

However, if we do another console.log(this) here, we see that it corresponds to Window because it is being used inside the function.

So this on line 29 is not the same as this on line 177, meaning that the argument this.entities passed to the WebVTTCueTextParser on line 177 will always be undefined. This causes a bug later on line 639 in the parser

if(self.entities[buffer]) {

Uncaught TypeError: Cannot read properties of undefined (reading '&M') where the buffer here is &M and self.entities is undefined.


Proposed Change

The proposed solution is to update how entities is passed to the WebVTTCueTextParser constructor on line 177 of parser.js:

Before:

var cuetextparser = new WebVTTCueTextParser(cue.text, err, mode, this.entities)

After:

var cuetextparser = new WebVTTCueTextParser(cue.text, err, mode, entities)

Steps to Reproduce:

const vttData = `
WEBVTT

1
00:11:46.140 --> 00:11:48.380
Texas A&M`

const { parse } = new WebVTTParser();
const parsed = parse(vttData, "metadata");
// ===> Uncaught TypeError: Cannot read properties of undefined (reading '&M')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants