Skip to content

Commit 31ea70c

Browse files
committed
"for each" fix, for modified prototypes
Fix "for..each" in case Array or Object prototypes are modified globally.
1 parent f1a4e65 commit 31ea70c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

functions/filesystem/pathinfo.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ function pathinfo(path, options) {
33
// original by: Nate
44
// revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
55
// improved by: Brett Zamir (http://brett-zamir.me)
6+
// improved by: Dmitry Gorelenkov
67
// input by: Timo
78
// note: Inspired by actual PHP source: php5-5.2.6/ext/standard/string.c line #1559
89
// note: The way the bitwise arguments are handled allows for greater flexibility
@@ -58,7 +59,9 @@ function pathinfo(path, options) {
5859
};
5960
// PATHINFO_ALL sums up all previously defined PATHINFOs (could just pre-calculate)
6061
for (optName in OPTS) {
61-
OPTS.PATHINFO_ALL = OPTS.PATHINFO_ALL | OPTS[optName];
62+
if(OPTS.hasOwnProperty(optName)){
63+
OPTS.PATHINFO_ALL = OPTS.PATHINFO_ALL | OPTS[optName];
64+
}
6265
}
6366
if (typeof options !== 'number') {
6467
// Allow for a single string or an array of string flags
@@ -123,12 +126,14 @@ function pathinfo(path, options) {
123126
// If array contains only 1 element: return string
124127
cnt = 0;
125128
for (opt in tmp_arr) {
126-
cnt++;
129+
if(tmp_arr.hasOwnProperty(opt)){
130+
cnt++;
131+
}
127132
}
128133
if (cnt == 1) {
129134
return tmp_arr[opt];
130135
}
131136

132137
// Return full-blown array
133138
return tmp_arr;
134-
}
139+
}

0 commit comments

Comments
 (0)