File tree 3 files changed +17
-6
lines changed
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,9 @@ function toRapidResponse(error) {
38
38
try {
39
39
if ( util . types . isNativeError ( error ) || _isError ( error ) ) {
40
40
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' ) ,
44
44
} ;
45
45
} else {
46
46
return {
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ class XRayFormattedCause {
50
50
51
51
let stack = [ ] ;
52
52
if ( err . stack ) {
53
- let stackLines = err . stack . split ( '\n' ) ;
53
+ let stackLines = err . stack . replace ( / \x7F / g , '%7F' ) . split ( '\n' ) ;
54
54
stackLines . shift ( ) ;
55
55
56
56
stackLines . forEach ( ( stackLine ) => {
@@ -79,8 +79,8 @@ class XRayFormattedCause {
79
79
80
80
this . exceptions = [
81
81
{
82
- type : err . name ,
83
- message : err . message ,
82
+ type : err . name ?. replace ( / \x7F / g , '%7F' ) ,
83
+ message : err . message ?. replace ( / \x7F / g , '%7F' ) ,
84
84
stack : stack ,
85
85
} ,
86
86
] ;
Original file line number Diff line number Diff line change @@ -19,3 +19,14 @@ describe('Formatted Error Logging', () => {
19
19
loggedError . should . have . property ( 'trace' ) . with . length ( 11 ) ;
20
20
} ) ;
21
21
} ) ;
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