Skip to content

Commit bc6c8bb

Browse files
committed
update to DOMPurify 3.2.6; related validation fix
1 parent 5c85b2f commit bc6c8bb

8 files changed

Lines changed: 423 additions & 1002 deletions

File tree

‎build/ableplayer.dist.js‎

Lines changed: 192 additions & 493 deletions
Large diffs are not rendered by default.

‎build/ableplayer.js‎

Lines changed: 192 additions & 493 deletions
Large diffs are not rendered by default.

‎build/ableplayer.min.css‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/ableplayer.min.js‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test": "jest"
1616
},
1717
"dependencies": {
18-
"dompurify": "^3.2.4",
18+
"dompurify": "^3.2.6",
1919
"dotenv": "^10.0.0",
2020
"jquery": "^3.5.0",
2121
"js-cookie": "^3.0.0",

‎scripts/__tests__/validate.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ describe("validate.js tests", () => {
6868
input: '<v class="first second">Some text</v>',
6969
expectedOutput: "<v.first.second>Some text</v>",
7070
},
71+
{
72+
description: "should postprocess <v> tags correctly, multiple attributes",
73+
input: '<v class="first second" title="Hello">Some text</v>',
74+
expectedOutput: '<v.first.second title="Hello">Some text</v>',
75+
},
76+
{
77+
description: "should postprocess <v> tags correctly, different attribute order",
78+
input: '<v title="Hello" class="first second">Some text</v>',
79+
expectedOutput: '<v.first.second title="Hello">Some text</v>',
80+
},
7181
{
7282
description: "should postprocess <lang> tags correctly",
7383
input: '<lang lang="en">Some text</lang>',

‎scripts/validate.js‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ var preProcessing = {
4040
},
4141

4242
/**
43-
* Transforms <v> tags by adding a title attribute with the concatenated text and retaining other attributes.
43+
* Transforms <v> tags by extracting any non-attribute text as a `title` attribute,
44+
* retains existing attributes (except class), and preserves the class attribute if present.
45+
* Example: <v John class="foo" data-x="y"> becomes <v title="John" data-x="y" class="foo">
46+
*
47+
* @function
4448
* @memberof preProcessing
45-
* @param {string} content - The content with processed <lang> tags.
46-
* @returns {string} - The content with <v> tags transformed.
49+
* @param {string} content - The string content containing <v> tags to process.
50+
* @returns {string} The content with <v> tags transformed to include a title attribute and preserved attributes.
4751
*/
4852
transformVTags: function (content) {
4953
return content.replace(/<v\s+([^>]*?)>/g, function (_, tagAttributes) {
@@ -109,17 +113,26 @@ var postProcessing = {
109113
},
110114

111115
/**
112-
* Post-processes <v> tags by converting class attributes to dot-separated class names.
116+
* * Post-processes <v> tags by converting class attributes, no matter where found in the attribute order, to dot-separated class names.
117+
* For example, <v class="foo bar" title="John"> becomes <v.foo.bar title="John">.
118+
* Removes the class attribute and appends other attributes after the class names.
119+
*
120+
* @function
113121
* @memberof postProcessing
114122
* @param {string} vttContent - The VTT content to be processed.
115123
* @returns {string} - The VTT content with processed <v> tags.
116124
*/
117125
postprocessVTag: function (vttContent) {
118126
return vttContent.replace(
119-
/<v class="([\w\s]+)"([^>]*)>/g,
120-
function (_, classNames, otherAttrs) {
121-
var classes = classNames.split(" ").join(".");
122-
return "<v." + classes + otherAttrs + ">";
127+
/<v([^>]*)class="([\w\s]+)"([^>]*)>/g,
128+
function (_, beforeClass, classNames, afterClass) {
129+
var classes = classNames.trim().split(/\s+/).join(".");
130+
// Rebuild the tag: <v.{classes}{other attributes}>
131+
// Remove class="..." from attributes
132+
var attrs = (beforeClass + afterClass)
133+
.replace(/\s*class="[\w\s]+"/, "")
134+
.trim();
135+
return "<v." + classes + (attrs ? " " + attrs : "") + ">";
123136
}
124137
);
125138
},

0 commit comments

Comments
 (0)