@@ -3,6 +3,7 @@ function pathinfo(path, options) {
3
3
// original by: Nate
4
4
// revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
5
5
// improved by: Brett Zamir (http://brett-zamir.me)
6
+ // improved by: Dmitry Gorelenkov
6
7
// input by: Timo
7
8
// note: Inspired by actual PHP source: php5-5.2.6/ext/standard/string.c line #1559
8
9
// note: The way the bitwise arguments are handled allows for greater flexibility
@@ -30,6 +31,7 @@ function pathinfo(path, options) {
30
31
// returns 7: {dirname: '/www/htdocs', basename: 'index.html', extension: 'html', filename: 'index'}
31
32
32
33
var opt = '' ,
34
+ real_opt = '' ,
33
35
optName = '' ,
34
36
optTemp = 0 ,
35
37
tmp_arr = { } ,
@@ -58,7 +60,9 @@ function pathinfo(path, options) {
58
60
} ;
59
61
// PATHINFO_ALL sums up all previously defined PATHINFOs (could just pre-calculate)
60
62
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
+ }
62
66
}
63
67
if ( typeof options !== 'number' ) {
64
68
// Allow for a single string or an array of string flags
@@ -123,12 +127,15 @@ function pathinfo(path, options) {
123
127
// If array contains only 1 element: return string
124
128
cnt = 0 ;
125
129
for ( opt in tmp_arr ) {
126
- cnt ++ ;
130
+ if ( tmp_arr . hasOwnProperty ( opt ) ) {
131
+ cnt ++ ;
132
+ real_opt = opt ;
133
+ }
127
134
}
128
- if ( cnt == 1 ) {
129
- return tmp_arr [ opt ] ;
135
+ if ( cnt === 1 ) {
136
+ return tmp_arr [ real_opt ] ;
130
137
}
131
138
132
139
// Return full-blown array
133
140
return tmp_arr ;
134
- }
141
+ }
0 commit comments