File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 55 * @param {Function } fn The function to stringify
66 */
77function normalizedFunctionString ( fn ) {
8- return fn . toString ( ) . replace ( ' function(' , 'function (' ) ;
8+ return fn . toString ( ) . replace ( / f u n c t i o n ( . * ) \( / , 'function (' ) ;
99}
1010
1111module . exports = {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ var Buffer = require('buffer').Buffer,
2222 vm = require ( 'vm' ) ;
2323
2424var createBSON = require ( '../utils' ) ;
25+ const normalizedFunctionString = require ( '../../lib/bson/parser/utils' ) . normalizedFunctionString ;
2526
2627// for tests
2728BSON . BSON_BINARY_SUBTYPE_DEFAULT = 0 ;
@@ -2346,4 +2347,17 @@ describe('BSON', function() {
23462347
23472348 expect ( bufferRaw ) . to . deep . equal ( uint8ArrayRaw ) ;
23482349 } ) ;
2350+
2351+ it ( 'Should normalize variations of the same function to the same string' , function ( ) {
2352+ const testObj = { test : function ( ) { } , test2 : function test2 ( ) { } } ;
2353+ const testFuncs = [
2354+ function ( ) { } ,
2355+ function func ( ) { } ,
2356+ function fUnCtIoN ( ) { } ,
2357+ testObj [ 'test' ] ,
2358+ testObj [ 'test2' ]
2359+ ] ;
2360+ const expectedString = 'function () {}' ;
2361+ testFuncs . forEach ( fn => expect ( normalizedFunctionString ( fn ) ) . to . equal ( expectedString ) ) ;
2362+ } ) ;
23492363} ) ;
You can’t perform that action at this time.
0 commit comments