File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,9 @@ function toRapidResponse(error) {
3838 try {
3939 if ( util . types . isNativeError ( error ) || _isError ( error ) ) {
4040 return {
41- errorType : error . name ,
42- errorMessage : error . message ,
43- trace : error . stack . split ( '\n' ) ,
41+ errorType : error . name ?. replace ( / \x7F / g , '%7F' ) ,
42+ errorMessage : error . message ?. replace ( / \x7F / g , '%7F' ) ,
43+ trace : error . stack . replace ( / \x7F / g , '%7F' ) . split ( '\n' ) ,
4444 } ;
4545 } else {
4646 return {
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ class XRayFormattedCause {
5050
5151 let stack = [ ] ;
5252 if ( err . stack ) {
53- let stackLines = err . stack . split ( '\n' ) ;
53+ let stackLines = err . stack . replace ( / \x7F / g , '%7F' ) . split ( '\n' ) ;
5454 stackLines . shift ( ) ;
5555
5656 stackLines . forEach ( ( stackLine ) => {
@@ -79,8 +79,8 @@ class XRayFormattedCause {
7979
8080 this . exceptions = [
8181 {
82- type : err . name ,
83- message : err . message ,
82+ type : err . name ?. replace ( / \x7F / g , '%7F' ) ,
83+ message : err . message ?. replace ( / \x7F / g , '%7F' ) ,
8484 stack : stack ,
8585 } ,
8686 ] ;
Original file line number Diff line number Diff line change @@ -19,3 +19,14 @@ describe('Formatted Error Logging', () => {
1919 loggedError . should . have . property ( 'trace' ) . with . length ( 11 ) ;
2020 } ) ;
2121} ) ;
22+
23+ describe ( 'Invalid chars in HTTP header' , ( ) => {
24+ it ( 'should be replaced' , ( ) => {
25+ let errorWithInvalidChar = new Error ( '\x7F \x7F' ) ;
26+ errorWithInvalidChar . name = 'ErrorWithInvalidChar' ;
27+
28+ let loggedError = Errors . toRapidResponse ( errorWithInvalidChar ) ;
29+ loggedError . should . have . property ( 'errorType' , 'ErrorWithInvalidChar' ) ;
30+ loggedError . should . have . property ( 'errorMessage' , '%7F %7F' ) ;
31+ } ) ;
32+ } ) ;
You can’t perform that action at this time.
0 commit comments