File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -95,10 +95,10 @@ function _headerToCamelCase(header) {
95
95
const newHeader = header . charAt ( 0 ) . toLowerCase ( ) + header . slice ( 1 )
96
96
97
97
// Converts headers in the form 'header-name' to be in the form 'headerName'
98
- // eslint-disable-next-line sonarjs/slow-regex
99
- return newHeader . replace ( / [ \W _ ] + ( \w ) / g , function capitalize ( m , $1 ) {
100
- return $1 . toUpperCase ( )
101
- } )
98
+ return newHeader . split ( / [ \W _ ] / ) . map ( ( ele , i ) => {
99
+ if ( i === 0 ) return ele
100
+ return ele . slice ( 0 , 1 ) . toUpperCase ( ) + ele . slice ( 1 )
101
+ } ) . join ( '' )
102
102
}
103
103
104
104
function _collectHeaders ( headers , nameMap , prefix , transaction ) {
Original file line number Diff line number Diff line change @@ -77,6 +77,23 @@ test('#collectRequestHeaders', async (t) => {
77
77
} )
78
78
} )
79
79
80
+ await t . test ( 'should replace repeating non-word characters' , ( t , end ) => {
81
+ const { agent } = t . nr
82
+ agent . config . allow_all_headers = true
83
+ const headers = {
84
+ 'foo-bar--baz' : 'valid-type'
85
+ }
86
+
87
+ helper . runInTransaction ( agent , ( transaction ) => {
88
+ headerAttributes . collectRequestHeaders ( headers , transaction )
89
+
90
+ const attributes = transaction . trace . attributes . get ( DESTINATIONS . TRANS_COMMON )
91
+ assert . equal ( attributes [ 'request.headers.fooBarBaz' ] , 'valid-type' )
92
+ assert . equal ( attributes [ 'foo-bar--baz' ] , undefined )
93
+ end ( )
94
+ } )
95
+ } )
96
+
80
97
await t . test ( 'should lowercase first letter in headers' , ( t , end ) => {
81
98
const { agent } = t . nr
82
99
const headers = {
You can’t perform that action at this time.
0 commit comments