File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change 1
1
import assertString from './util/assertString' ;
2
2
import merge from './util/merge' ;
3
3
4
- const base64WithPadding = / ^ (?: [ A - Z a - z 0 - 9 + / ] { 4 } ) * (?: [ A - Z a - z 0 - 9 + / ] { 2 } = = | [ A - Z a - z 0 - 9 + / ] { 3 } = | [ A - Z a - z 0 - 9 + / ] { 4 } ) $ / ;
4
+ const base64WithPadding = / ^ [ A - Z a - z 0 - 9 + / ] + = { 0 , 2 } $ / ;
5
5
const base64WithoutPadding = / ^ [ A - Z a - z 0 - 9 + / ] + $ / ;
6
- const base64UrlWithPadding = / ^ (?: [ A - Z a - z 0 - 9 _ - ] { 4 } ) * (?: [ A - Z a - z 0 - 9 _ - ] { 2 } = = | [ A - Z a - z 0 - 9 _ - ] { 3 } = | [ A - Z a - z 0 - 9 _ - ] { 4 } ) $ / ;
6
+ const base64UrlWithPadding = / ^ [ A - Z a - z 0 - 9 _ - ] + = { 0 , 2 } $ / ;
7
7
const base64UrlWithoutPadding = / ^ [ A - Z a - z 0 - 9 _ - ] + $ / ;
8
8
9
9
export default function isBase64 ( str , options ) {
@@ -12,6 +12,8 @@ export default function isBase64(str, options) {
12
12
13
13
if ( str === '' ) return true ;
14
14
15
+ if ( options . padding && str . length % 4 !== 0 ) return false ;
16
+
15
17
let regex ;
16
18
if ( options . urlSafe ) {
17
19
regex = options . padding ? base64UrlWithPadding : base64UrlWithoutPadding ;
You can’t perform that action at this time.
0 commit comments