Skip to content

Commit 51cec2e

Browse files
author
Kevin Lentin
committed
validatorjs#2491 validatorjs#2573 Simplify isBase64 to prevent stack overflow
1 parent 72573b3 commit 51cec2e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
registry=https://repo.tools.telstra.com/repository/npm-group/
2+
@telstra-nso:registry=https://repo.tools.telstra.com/repository/ucdm/
3+
//repo.tools.telstra.com/repository/npm-group/:_auth=${NPM_AUTHTOKEN}
4+
//repo.tools.telstra.com/repository/ucdm/:_auth=${NPM_AUTHTOKEN}

src/lib/isBase64.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import assertString from './util/assertString';
22
import merge from './util/merge';
33

4-
const base64WithPadding = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;
4+
const base64WithPadding = /^[A-Za-z0-9+/]+={0,2}$/;
55
const base64WithoutPadding = /^[A-Za-z0-9+/]+$/;
6-
const base64UrlWithPadding = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}==|[A-Za-z0-9_-]{3}=|[A-Za-z0-9_-]{4})$/;
6+
const base64UrlWithPadding = /^[A-Za-z0-9_-]+={0,2}$/;
77
const base64UrlWithoutPadding = /^[A-Za-z0-9_-]+$/;
88

99
export default function isBase64(str, options) {
@@ -12,6 +12,8 @@ export default function isBase64(str, options) {
1212

1313
if (str === '') return true;
1414

15+
if (options.padding && str.length % 4 !== 0) return false;
16+
1517
let regex;
1618
if (options.urlSafe) {
1719
regex = options.padding ? base64UrlWithPadding : base64UrlWithoutPadding;

0 commit comments

Comments
 (0)