Skip to content

Commit

Permalink
Protecting against Opera Mini modulo operator bug (Issue #496)
Browse files Browse the repository at this point in the history
Former-commit-id: 1cf9438
  • Loading branch information
andrewplummer committed Sep 28, 2015
1 parent 29278ae commit 5cb6e0c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/array.js
Expand Up @@ -1146,7 +1146,7 @@
* [1,2,3].at(4) -> 2
* [1,2,3].at(4, false) -> null
* [1,2,3].at(-1) -> 3
* [1,2,3].at(0,1) -> [1,2]
* [1,2,3].at(0, 1) -> [1,2]
*
***/
'at': function(arr, args) {
Expand Down
2 changes: 1 addition & 1 deletion lib/common.js
Expand Up @@ -461,7 +461,7 @@
}

function entryAtIndex(obj, length, index, overshoot, isString) {
if (overshoot) {
if (overshoot && index) {
index = index % length;
if (index < 0) index = length + index;
}
Expand Down
14 changes: 4 additions & 10 deletions lib/date.js
Expand Up @@ -234,16 +234,10 @@
} else if (loc[key + 's']) {
value = loc[key + 's'];
if (slice) {
// Can't use filter here as Prototype hijacks the method and doesn't
// pass an index, so use a simple loop instead!
arr = [];
value.forEach(function(m, i) {
value = value.filter(function(m, i) {
var mod = i % (loc.units ? 8 : value.length);
if (mod >= slice[1] && mod <= (slice[2] || slice[1])) {
arr.push(m);
}
return mod >= slice[1] && mod <= (slice[2] || slice[1]);
});
value = arr;
}
value = arrayToAlternates(value);
}
Expand Down Expand Up @@ -566,7 +560,7 @@
}

function setWeekday(d, dow, forward) {
if (isUndefined(dow)) return;
if (!isNumber(dow)) return;
// Dates like "the 2nd Tuesday of June" need to be set forward
// so make sure that the day of the week reflects that here.
if (forward && dow % 7 < d.getDay()) {
Expand Down Expand Up @@ -920,7 +914,7 @@
}

iterateOverDateUnits(function(name, unit, i) {
var value = set[name], fraction = value % 1;
var value = set[name] || 0, fraction = value % 1;
if (fraction) {
set[dateUnitsReversed[i - 1].name] = round(fraction * (name === 'second' ? 1000 : 60));
set[name] = floor(value);
Expand Down

0 comments on commit 5cb6e0c

Please sign in to comment.