Skip to content

Commit 6d87bfe

Browse files
authored
fix(isSlug & rtrim): regex no longer exposed to ReDOS attacks (#1603)
1 parent 2331120 commit 6d87bfe

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib/isSlug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assertString from './util/assertString';
22

3-
let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})([a-z0-9-\\]{1,})[^\s]*[^-_\s]$/;
3+
let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;
44

55
export default function isSlug(str) {
66
assertString(str);

src/lib/rtrim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import assertString from './util/assertString';
33
export default function rtrim(str, chars) {
44
assertString(str);
55
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
6-
const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /\s+$/g;
6+
const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g;
77
return str.replace(pattern, '');
88
}

0 commit comments

Comments
 (0)