Skip to content

Commit 905a1f0

Browse files
Merge pull request #58 from contentstack/next
SRE fixes
2 parents 54e1fc7 + b51cdc8 commit 905a1f0

File tree

6 files changed

+253
-24
lines changed

6 files changed

+253
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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)

package-lock.json

Lines changed: 185 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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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",
@@ -39,6 +39,7 @@
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",
@@ -48,8 +49,8 @@
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",
@@ -80,5 +81,9 @@
8081
"presets": [
8182
"es2015"
8283
]
84+
},
85+
"dependencies": {
86+
"cheerio": "^1.0.0-rc.12",
87+
"dompurify": "^3.1.1"
8388
}
8489
}

src/helper/regex-match.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
const FigureTagRegex = /<\s*figure[^>]*>([^]*?)<\s*\/\s*figure>/g;
2-
31
export 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

1127
export function countFigureTags(content: string): number {

0 commit comments

Comments
 (0)