File tree Expand file tree Collapse file tree 6 files changed +253
-24
lines changed
Expand file tree Collapse file tree 6 files changed +253
-24
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3- ## [ 1.3.3] ( https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.2 ) (2024-02-28)
3+ ## [ 1.3.4] ( https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.4 ) (2024-05-13)
4+ - Fixes for vulnerability issues related to regular expression and options
5+
6+ ## [ 1.3.3] ( https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.3 ) (2024-02-28)
47 - Fix for parsing nested children when entry is referenced as link
58
69## [ 1.3.2] ( https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.2 ) (2024-02-14)
Original file line number Diff line number Diff line change 11{
22 "name" : " @contentstack/utils" ,
3- "version" : " 1.3.3 " ,
3+ "version" : " 1.3.4 " ,
44 "description" : " Contentstack utilities for Javascript" ,
55 "main" : " dist/index.es.js" ,
66 "types" : " dist/types/index.d.ts" ,
3939 "@babel/preset-env" : " ^7.22.20" ,
4040 "@commitlint/cli" : " ^17.7.1" ,
4141 "@commitlint/config-conventional" : " ^17.7.0" ,
42+ "@types/dompurify" : " ^3.0.5" ,
4243 "@types/jest" : " ^26.0.24" ,
4344 "babel-core" : " ^4.7.16" ,
4445 "babel-jest" : " ^29.7.0" ,
4849 "eslint" : " ^8.50.0" ,
4950 "husky" : " ^8.0.3" ,
5051 "jest" : " ^29.7.0" ,
51- "jest-environment-jsdom" : " ^29.7.0" ,
5252 "jest-coverage-badges" : " ^1.1.2" ,
53+ "jest-environment-jsdom" : " ^29.7.0" ,
5354 "jest-html-reporters" : " ^2.1.7" ,
5455 "jest-junit" : " ^15.0.0" ,
5556 "jsdom" : " ^21.1.2" ,
8081 "presets" : [
8182 " es2015"
8283 ]
84+ },
85+ "dependencies" : {
86+ "cheerio" : " ^1.0.0-rc.12" ,
87+ "dompurify" : " ^3.1.1"
8388 }
8489}
Original file line number Diff line number Diff line change 1- const FigureTagRegex = / < \s * f i g u r e [ ^ > ] * > ( [ ^ ] * ?) < \s * \/ \s * f i g u r e > / g;
2-
31export function containsFigureTag ( content : string ) : boolean {
4- return countFigureTags ( content ) > 0 ;
2+ const openingTag = '<figure' ;
3+ const closingTag = '</figure>' ;
4+ const openingIndex = content . indexOf ( openingTag ) ;
5+ const closingIndex = content . indexOf ( closingTag ) ;
6+ return openingIndex !== - 1 && closingIndex !== - 1 && closingIndex > openingIndex ;
57}
68
7- export function matchFigureTag ( content : string ) : RegExpMatchArray {
8- return content . match ( FigureTagRegex ) ;
9+ export function matchFigureTag ( content : string ) : string [ ] | null {
10+ const matches : string [ ] = [ ] ;
11+ const openingTag = '<figure' ;
12+ const closingTag = '</figure>' ;
13+ let startIndex = 0 ;
14+ while ( ( startIndex = content . indexOf ( openingTag , startIndex ) ) !== - 1 ) {
15+ const endIndex = content . indexOf ( closingTag , startIndex ) ;
16+ if ( endIndex !== - 1 && endIndex > startIndex ) {
17+ matches . push ( content . substring ( startIndex , endIndex + closingTag . length ) ) ;
18+ startIndex = endIndex + closingTag . length ;
19+ } else {
20+ console . error ( 'Malformed figure tag found in content' ) ;
21+ break ;
22+ }
23+ }
24+ return matches . length > 0 ? matches : null ;
925}
1026
1127export function countFigureTags ( content : string ) : number {
You can’t perform that action at this time.
0 commit comments