@@ -7504,13 +7504,60 @@ var AblePlayerInstances = [];
75047504 };
75057505
75067506 AblePlayer.prototype.sanitizeVttData = function (vttData) {
7507- // Function to preprocess <c> tags
7508- function preprocessCTag(vttData) {
7509- return vttData.replace(/<c\.([\w.]+)>/g, function (match, classNames) {
7510- var classes = classNames.split(".").join(" ");
7511- return '<c class="' + classes + '">';
7512- });
7507+ // Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
7508+ // Combined function to process <v> tags and preprocess <v.word.word> and <c.word.word> tags
7509+ function processAndPreprocessTags(html) {
7510+ // First, preprocess <v.word.word> and <c.word.word> tags
7511+ var preprocessedHtml = html.replace(
7512+ /<(v|c)\.([\w\.]+)([^>]*)>/g,
7513+ function (match, tag, words, otherAttrs) {
7514+ var classAttr = words.split(".").join(" ");
7515+ return "<" + tag + ' class="' + classAttr + '"' + otherAttrs + ">";
7516+ }
7517+ );
7518+
7519+ // Then, process <v> tags to add title attribute and handle class attribute correctly
7520+ var processedHtml = preprocessedHtml.replace(
7521+ /<v\s+([^>]*?)>/g,
7522+ function (match, p1) {
7523+ // Extract class attribute if present
7524+ var classMatch = p1.match(/class="([^"]*)"/);
7525+ var classAttr = classMatch ? classMatch[0] : "";
7526+
7527+ // Remove class attribute from p1 to process the title
7528+ var p1WithoutClass = p1.replace(/class="[^"]*"/, "").trim();
7529+
7530+ // Split the remaining content by spaces
7531+ var parts = p1WithoutClass.split(/\s+/);
7532+ var attributes = [];
7533+ var titleParts = [];
7534+
7535+ // Separate attributes and title parts
7536+ parts.forEach(function (part) {
7537+ if (part.indexOf("=") !== -1) {
7538+ attributes.push(part);
7539+ } else {
7540+ titleParts.push(part);
7541+ }
7542+ });
7543+
7544+ // Construct the new <v> tag
7545+ var title = titleParts.join(" ");
7546+ var newTag =
7547+ '<v title="' +
7548+ title +
7549+ '" ' +
7550+ attributes.join(" ") +
7551+ " " +
7552+ classAttr +
7553+ ">";
7554+ return newTag;
7555+ }
7556+ );
7557+
7558+ return processedHtml;
75137559 }
7560+
75147561 // Function to postprocess <c> tags
75157562 function postprocessCTag(vttData) {
75167563 return vttData.replace(
@@ -7521,33 +7568,20 @@ var AblePlayerInstances = [];
75217568 }
75227569 );
75237570 }
7524- // Function to process <v> tags
7525- function processVTag(vttData) {
7526- return vttData.replace(/<v\s+([^>]*?)>/g, function (match, p1) {
7527- // Split the content by spaces
7528- var parts = p1.split(/\s+/);
7529- var attributes = [];
7530- var titleParts = [];
7531-
7532- // Separate attributes and title parts
7533- parts.forEach(function (part) {
7534- if (part.indexOf("=") !== -1) {
7535- attributes.push(part);
7536- } else {
7537- titleParts.push(part);
7538- }
7539- });
75407571
7541- // Construct the new <v> tag
7542- var title = titleParts.join(" ");
7543- var newTag = '<v title="' + title + '" ' + attributes.join(" ") + ">";
7544- return newTag;
7545- });
7572+ // Function to postprocess <v> tags
7573+ function postprocessVTag(vttData) {
7574+ return vttData.replace(
7575+ /<v class="([\w\s]+)"([^>]*)>/g,
7576+ function (match, classNames, otherAttrs) {
7577+ var classes = classNames.split(" ").join(".");
7578+ return "<v." + classes + otherAttrs + ">";
7579+ }
7580+ );
75467581 }
7547- // Preprocess <c> tags before sanitizing
7548- vttData = preprocessCTag(vttData);
7549- // Process <v> tags before sanitizing
7550- vttData = processVTag(vttData);
7582+
7583+ // Process <v> and <c> attribute processing
7584+ vttData = processAndPreprocessTags(vttData);
75517585
75527586 // Configure DOMPurify
75537587 var config = {
@@ -7561,6 +7595,7 @@ var AblePlayerInstances = [];
75617595
75627596 // Postprocessing after sanitizing
75637597 sanitizedVttData = postprocessCTag(sanitizedVttData);
7598+ sanitizedVttData = postprocessVTag(sanitizedVttData);
75647599
75657600 sanitizedVttData = sanitizedVttData.replace(/-->/g, "-->");
75667601
0 commit comments