@@ -257,7 +257,7 @@ module.exports = {
257
257
if ( ! host ) host = this . get ( 'Host' ) ;
258
258
}
259
259
if ( ! host ) return '' ;
260
- return host . split ( / \s * , \s * / , 1 ) [ 0 ] ;
260
+ return splitCommaSeparatedValues ( host , 1 ) [ 0 ] ;
261
261
} ,
262
262
263
263
/**
@@ -402,7 +402,7 @@ module.exports = {
402
402
if ( this . socket . encrypted ) return 'https' ;
403
403
if ( ! this . app . proxy ) return 'http' ;
404
404
const proto = this . get ( 'X-Forwarded-Proto' ) ;
405
- return proto ? proto . split ( / \s * , \s * / , 1 ) [ 0 ] : 'http' ;
405
+ return proto ? splitCommaSeparatedValues ( proto , 1 ) [ 0 ] : 'http' ;
406
406
} ,
407
407
408
408
/**
@@ -434,7 +434,7 @@ module.exports = {
434
434
const proxy = this . app . proxy ;
435
435
const val = this . get ( this . app . proxyIpHeader ) ;
436
436
let ips = proxy && val
437
- ? val . split ( / \s * , \s * / )
437
+ ? splitCommaSeparatedValues ( val )
438
438
: [ ] ;
439
439
if ( this . app . maxIpsCount > 0 ) {
440
440
ips = ips . slice ( - this . app . maxIpsCount ) ;
@@ -724,3 +724,15 @@ module.exports = {
724
724
if ( util . inspect . custom ) {
725
725
module . exports [ util . inspect . custom ] = module . exports . inspect ;
726
726
}
727
+
728
+ /**
729
+ * Split a comma-separated value string into an array of values, with an optional limit.
730
+ * All the values are trimmed of whitespace.
731
+ *
732
+ * @param {string } value - The comma-separated value string to split.
733
+ * @param {number } [limit] - The maximum number of values to return.
734
+ * @returns {string[] } An array of values from the comma-separated string.
735
+ */
736
+ function splitCommaSeparatedValues ( value , limit ) {
737
+ return value . split ( ',' , limit ) . map ( v => v . trim ( ) ) ;
738
+ }
0 commit comments