Skip to content

Commit a1e6041

Browse files
fix: added support for special symbols in regex and added tpe support for includeContentType param
1 parent 507f495 commit a1e6041

6 files changed

Lines changed: 17 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Version: 5.1.1
2+
#### Date: Mar-09-2026
3+
Fix: Added support of special symbols in regex method with safe pattern.
4+
15
### Version: 5.1.0
26
#### Date: Mar-02-2026
37
Fix: Added support of asset fields in assets & entries class.

package-lock.json

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.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/delivery-sdk",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"type": "module",
55
"license": "MIT",
66
"engines": {

src/common/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ export interface BaseContentType {
337337
schema: any;
338338
}
339339

340-
export interface FindResponse<T> {
340+
export interface FindResponse<T, TContentType = unknown> {
341341
entries?: T[];
342-
content_types?: T[];
342+
content_type?: TContentType;
343+
content_types?: TContentType[];
343344
assets?: T[];
344345
global_fields?: T[];
345346
count?: number;

src/query/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Query extends BaseQuery {
3434
// Expanded whitelist: includes spaces and common safe special characters
3535
// Allows: alphanumeric, regex metacharacters, regular spaces, and common punctuation
3636
// Blocks: control characters (newlines, tabs, null bytes), backticks, and other dangerous chars
37-
const validRegex = /^[a-zA-Z0-9|^$.*+?()[\]{}:,;&@#%=/!'"_~<> -]+$/;
37+
const validRegex = /^[a-zA-Z0-9|^$.*+?()[\]{}\\:,;&@#%=/!'"_~<>` -]+$/;
3838
if (!validRegex.test(input)) {
3939
return false;
4040
}

test/unit/query.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ describe('Query class', () => {
137137
expect(regexQuery._parameters['email'].$regex).toBe('.*@example.com.*');
138138
});
139139

140+
it('should accept escaped regex metacharacters from user input', () => {
141+
const regexQuery = getQueryObject(client, 'contentTypeUid');
142+
expect(() => regexQuery.regex('title', '.*debt\\?.*', 'i')).not.toThrow();
143+
expect(regexQuery._parameters['title']).toEqual({ $regex: '.*debt\\?.*', $options: 'i' });
144+
});
145+
140146
it('should accept regex pattern with semicolon, equals, slash', () => {
141147
const regexQuery = getQueryObject(client, 'contentTypeUid');
142148
expect(() => regexQuery.regex('url', '.*https://example.com.*', 'i')).not.toThrow();

0 commit comments

Comments
 (0)