Skip to content

Escape entities not correctly parsed/escaped #36

Description

@RaminRabani

A prerequisite to this bug is to fix the bug described in #35.

When the entities object is correctly passed to the WebVTTCueTextParser on line 177 as described in the issue above, there are some problems with parsing escape entities.

Steps to Reproduce

const { parse } = new WebVTTParser({
  "&amp": "&",
  "&": "&",
  "&": "&",
  "&AMP": "&",
});

const text1 = `
WEBVTT

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

const text2 = `
WEBVTT

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

const text3 = `
WEBVTT

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

const parsed1 = parse(text1, "metadata");
console.log(parsed1.cues[0].tree.children[0].value); // Texas A&M (correctly parsed)

const parsed2 = parse(text2, "metadata");
console.log(parsed2.cues[0].tree.children[0].value); // Texas A& (correctly parsed)

const parsed3 = parse(text3, "metadata");
console.log(parsed3.cues[0].tree.children[0].value); // Texas A&ampM (incorrectly parsed)

As you can see if the escape characters &amp are not followed by ; or the end of the string (undefined) but instead followed by another alphanumeric character, the escape characters are not properly parsed.

Solution

I believe some conditional logic needs to be updated or added in lines 632-670 to account for escape entities that are followed by an alphanumeric character.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions