@@ -257,7 +257,7 @@ module.exports = {
257257 if ( ! host ) host = this . get ( 'Host' ) ;
258258 }
259259 if ( ! host ) return '' ;
260- return host . split ( / \s * , \s * / , 1 ) [ 0 ] ;
260+ return splitCommaSeparatedValues ( host , 1 ) [ 0 ] ;
261261 } ,
262262
263263 /**
@@ -402,7 +402,7 @@ module.exports = {
402402 if ( this . socket . encrypted ) return 'https' ;
403403 if ( ! this . app . proxy ) return 'http' ;
404404 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' ;
406406 } ,
407407
408408 /**
@@ -434,7 +434,7 @@ module.exports = {
434434 const proxy = this . app . proxy ;
435435 const val = this . get ( this . app . proxyIpHeader ) ;
436436 let ips = proxy && val
437- ? val . split ( / \s * , \s * / )
437+ ? splitCommaSeparatedValues ( val )
438438 : [ ] ;
439439 if ( this . app . maxIpsCount > 0 ) {
440440 ips = ips . slice ( - this . app . maxIpsCount ) ;
@@ -724,3 +724,15 @@ module.exports = {
724724if ( util . inspect . custom ) {
725725 module . exports [ util . inspect . custom ] = module . exports . inspect ;
726726}
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