@@ -32,13 +32,15 @@ export class Utils {
3232 return hash ;
3333 }
3434
35- public static getCookies ( cookies :string ) : Object {
35+ public static getCookies ( cookies :string , exclusions ?: string [ ] ) : Object {
3636 let result :Object = { } ;
3737
3838 let parts :string [ ] = ( cookies || '' ) . split ( '; ' ) ;
3939 for ( let index = 0 ; index < parts . length ; index ++ ) {
4040 let cookie :string [ ] = parts [ index ] . split ( '=' ) ;
41- result [ cookie [ 0 ] ] = cookie [ 1 ] ;
41+ if ( ! Utils . isMatch ( cookie [ 0 ] , exclusions ) ) {
42+ result [ cookie [ 0 ] ] = cookie [ 1 ] ;
43+ }
4244 }
4345
4446 return result ;
@@ -84,7 +86,7 @@ export class Utils {
8486 return null ;
8587 }
8688
87- public static parseQueryString ( query :string ) {
89+ public static parseQueryString ( query :string , exclusions ?: string [ ] ) {
8890 if ( ! query || query . length === 0 ) {
8991 return null ;
9092 }
@@ -97,7 +99,9 @@ export class Utils {
9799 let result :Object = { } ;
98100 for ( let index = 0 ; index < pairs . length ; index ++ ) {
99101 let pair = pairs [ index ] . split ( '=' ) ;
100- result [ decodeURIComponent ( pair [ 0 ] ) ] = decodeURIComponent ( pair [ 1 ] ) ;
102+ if ( ! Utils . isMatch ( pair [ 0 ] , exclusions ) ) {
103+ result [ decodeURIComponent ( pair [ 0 ] ) ] = decodeURIComponent ( pair [ 1 ] ) ;
104+ }
101105 }
102106
103107 return result ;
@@ -108,20 +112,23 @@ export class Utils {
108112 }
109113
110114 /**
111- * Stringifys an object with optional exclusions and max depth.
112- * @param data The data object to add.
113- * @param exclusions Any property names that should be excluded.
114- * @param maxDepth The max depth of the object to include.
115+ * Checks to see if a value matches a pattern.
116+ * @param input the value to check against the @pattern.
117+ * @param pattern The pattern to check, supports wild cards (*).
115118 */
116- public static stringify ( data :any , exclusions ?:string [ ] , maxDepth ?:number ) : string {
117- function checkForMatch ( pattern :string , value :string ) : boolean {
118- if ( ! pattern || ! value || typeof value !== 'string' ) {
119+ public static isMatch ( input :string , patterns :string [ ] ) :boolean {
120+ if ( ! input || typeof input !== 'string' ) {
121+ return false ;
122+ }
123+
124+ let trim = / ^ [ \s \uFEFF \xA0 ] + | [ \s \uFEFF \xA0 ] + $ / g;
125+ return ( patterns || [ ] ) . some ( pattern => {
126+ if ( ! pattern ) {
119127 return false ;
120128 }
121129
122- let trim = / ^ [ \s \uFEFF \xA0 ] + | [ \s \uFEFF \xA0 ] + $ / g;
123130 pattern = pattern . toLowerCase ( ) . replace ( trim , '' ) ;
124- value = value . toLowerCase ( ) . replace ( trim , '' ) ;
131+ input = input . toLowerCase ( ) . replace ( trim , '' ) ;
125132
126133 if ( pattern . length <= 0 ) {
127134 return false ;
@@ -138,27 +145,33 @@ export class Utils {
138145 }
139146
140147 if ( startsWithWildcard && endsWithWildcard ) {
141- return value . indexOf ( pattern ) !== - 1 ;
148+ return input . indexOf ( pattern ) !== - 1 ;
142149 }
143150
144151 if ( startsWithWildcard ) {
145- return value . lastIndexOf ( pattern ) === ( value . length - pattern . length ) ;
152+ return input . lastIndexOf ( pattern ) === ( input . length - pattern . length ) ;
146153 }
147154
148155 if ( endsWithWildcard ) {
149- return value . indexOf ( pattern ) === 0 ;
156+ return input . indexOf ( pattern ) === 0 ;
150157 }
151158
152- return value === pattern ;
153- }
159+ return input === pattern ;
160+ } ) ;
161+ }
154162
163+ /**
164+ * Stringifys an object with optional exclusions and max depth.
165+ * @param data The data object to add.
166+ * @param exclusions Any property names that should be excluded.
167+ * @param maxDepth The max depth of the object to include.
168+ */
169+ public static stringify ( data :any , exclusions ?:string [ ] , maxDepth ?:number ) : string {
155170 function stringifyImpl ( obj :any , excludedKeys :string [ ] ) : string {
156171 let cache :string [ ] = [ ] ;
157172 return JSON . stringify ( obj , function ( key :string , value :any ) {
158- for ( let index = 0 ; index < ( excludedKeys || [ ] ) . length ; index ++ ) {
159- if ( checkForMatch ( excludedKeys [ index ] , key ) ) {
160- return ;
161- }
173+ if ( Utils . isMatch ( key , excludedKeys ) ) {
174+ return ;
162175 }
163176
164177 if ( typeof value === 'object' && ! ! value ) {
@@ -177,12 +190,12 @@ export class Utils {
177190 if ( ( { } ) . toString . call ( data ) === '[object Array]' ) {
178191 let result = [ ] ;
179192 for ( let index = 0 ; index < data . length ; index ++ ) {
180- result [ index ] = JSON . parse ( stringifyImpl ( data [ index ] , exclusions || [ ] ) ) ;
193+ result [ index ] = JSON . parse ( stringifyImpl ( data [ index ] , exclusions ) ) ;
181194 }
182195
183196 return JSON . stringify ( result ) ;
184197 }
185198
186- return stringifyImpl ( data , exclusions || [ ] ) ;
199+ return stringifyImpl ( data , exclusions ) ;
187200 }
188201}
0 commit comments