Skip to content

Commit 6342ca2

Browse files
committed
Fix for issue #101
1 parent 4d1e835 commit 6342ca2

File tree

4 files changed

+1203
-1173
lines changed

4 files changed

+1203
-1173
lines changed

‎BigInteger.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1038,14 +1038,31 @@ var bigInt = (function (undefined) {
10381038
}
10391039
var parseBase = function (text, base) {
10401040
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-z0-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+
}
10411055
if (2 <= base && base <= 36) {
10421056
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+
}
10431061
return new SmallInteger(parseInt(text, base));
10441062
}
10451063
}
10461064
base = parseValue(base);
10471065
var digits = [];
1048-
var i;
10491066
var isNegative = text[0] === "-";
10501067
for (i = isNegative ? 1 : 0; i < text.length; i++) {
10511068
var c = text[i].toLowerCase(),

0 commit comments

Comments
 (0)