Skip to content

Commit 6a322e4

Browse files
committed
Merge pull request locutusjs#161 from yadimon/patch-2
"for each" fix, for modified prototypes
2 parents f1a4e65 + 3f2a975 commit 6a322e4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

functions/filesystem/pathinfo.js

Lines changed: 12 additions & 5 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
@@ -30,6 +31,7 @@ function pathinfo(path, options) {
3031
// returns 7: {dirname: '/www/htdocs', basename: 'index.html', extension: 'html', filename: 'index'}
3132

3233
var opt = '',
34+
real_opt = '',
3335
optName = '',
3436
optTemp = 0,
3537
tmp_arr = {},
@@ -58,7 +60,9 @@ function pathinfo(path, options) {
5860
};
5961
// PATHINFO_ALL sums up all previously defined PATHINFOs (could just pre-calculate)
6062
for (optName in OPTS) {
61-
OPTS.PATHINFO_ALL = OPTS.PATHINFO_ALL | OPTS[optName];
63+
if(OPTS.hasOwnProperty(optName)){
64+
OPTS.PATHINFO_ALL = OPTS.PATHINFO_ALL | OPTS[optName];
65+
}
6266
}
6367
if (typeof options !== 'number') {
6468
// Allow for a single string or an array of string flags
@@ -123,12 +127,15 @@ function pathinfo(path, options) {
123127
// If array contains only 1 element: return string
124128
cnt = 0;
125129
for (opt in tmp_arr) {
126-
cnt++;
130+
if(tmp_arr.hasOwnProperty(opt)){
131+
cnt++;
132+
real_opt = opt;
133+
}
127134
}
128-
if (cnt == 1) {
129-
return tmp_arr[opt];
135+
if (cnt === 1) {
136+
return tmp_arr[real_opt];
130137
}
131138

132139
// Return full-blown array
133140
return tmp_arr;
134-
}
141+
}

0 commit comments

Comments
 (0)