Skip to content

Commit 2ce8861

Browse files
authored
Handle invalid char when sending HTTP request to Runtime API (#100)
1 parent eeac0b3 commit 2ce8861

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Diff for: src/Errors.js

+3-3
Original file line numberDiff line numberDiff 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 {

Diff for: src/XRayError.js

+3-3
Original file line numberDiff line numberDiff 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
];

Diff for: test/unit/ErrorsTest.js

+11
Original file line numberDiff line numberDiff 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+
});

0 commit comments

Comments
 (0)