File tree 4 files changed +1203
-1173
lines changed
4 files changed +1203
-1173
lines changed Original file line number Diff line number Diff line change @@ -1038,14 +1038,31 @@ var bigInt = (function (undefined) {
1038
1038
}
1039
1039
var parseBase = function ( text , base ) {
1040
1040
var length = text . length ;
1041
+ var i ;
1042
+ var absBase = Math . abs ( base ) ;
1043
+ for ( var i = 0 ; i < length ; i ++ ) {
1044
+ var c = text [ i ] . toLowerCase ( ) ;
1045
+ if ( c === "-" ) continue ;
1046
+ if ( / [ a - z 0 - 9 ] / . test ( c ) ) {
1047
+ if ( / [ 0 - 9 ] / . test ( c ) && + c >= absBase ) {
1048
+ if ( c === "1" && absBase === 1 ) continue ;
1049
+ throw new Error ( c + " is not a valid digit in base " + base + "." ) ;
1050
+ } else if ( c . charCodeAt ( 0 ) - 87 >= absBase ) {
1051
+ throw new Error ( c + " is not a valid digit in base " + base + "." ) ;
1052
+ }
1053
+ }
1054
+ }
1041
1055
if ( 2 <= base && base <= 36 ) {
1042
1056
if ( length <= LOG_MAX_INT / Math . log ( base ) ) {
1057
+ var result = parseInt ( text , base ) ;
1058
+ if ( isNaN ( result ) ) {
1059
+ throw new Error ( c + " is not a valid digit in base " + base + "." ) ;
1060
+ }
1043
1061
return new SmallInteger ( parseInt ( text , base ) ) ;
1044
1062
}
1045
1063
}
1046
1064
base = parseValue ( base ) ;
1047
1065
var digits = [ ] ;
1048
- var i ;
1049
1066
var isNegative = text [ 0 ] === "-" ;
1050
1067
for ( i = isNegative ? 1 : 0 ; i < text . length ; i ++ ) {
1051
1068
var c = text [ i ] . toLowerCase ( ) ,
You can’t perform that action at this time.
0 commit comments