File tree 4 files changed +16
-2
lines changed
4 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export class Code extends BSONValue {
62
62
63
63
inspect ( ) : string {
64
64
const codeJson = this . toJSON ( ) ;
65
- return `new Code(" ${ String ( codeJson . code ) } " ${
65
+ return `new Code(${ JSON . stringify ( String ( codeJson . code ) ) } ${
66
66
codeJson . scope != null ? `, ${ JSON . stringify ( codeJson . scope ) } ` : ''
67
67
} )`;
68
68
}
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export class BSONSymbol extends BSONValue {
34
34
}
35
35
36
36
inspect ( ) : string {
37
- return `new BSONSymbol(" ${ this . value } " )` ;
37
+ return `new BSONSymbol(${ JSON . stringify ( this . value ) } )` ;
38
38
}
39
39
40
40
toJSON ( ) : string {
Original file line number Diff line number Diff line change 1
1
import { expect } from 'chai' ;
2
2
import * as BSON from '../register-bson' ;
3
+ import { inspect } from 'util' ;
3
4
4
5
describe ( 'class Code' , ( ) => {
5
6
it ( 'defines a nodejs inspect method' , ( ) => {
@@ -8,6 +9,13 @@ describe('class Code', () => {
8
9
. that . is . a ( 'function' ) ;
9
10
} ) ;
10
11
12
+ it ( 'prints re-evaluatable output for Code that contains quotes' , ( ) => {
13
+ const codeStringInput = new BSON . Code ( 'function a(){ return "asdf"; }' ) ;
14
+ expect ( inspect ( codeStringInput ) ) . to . equal (
15
+ String . raw `new Code("function a(){ return \"asdf\"; }")`
16
+ ) ;
17
+ } ) ;
18
+
11
19
describe ( 'new Code()' , ( ) => {
12
20
it ( 'defines a code property that is a string' , ( ) => {
13
21
const codeStringInput = new BSON . Code ( 'function a(){}' ) ;
Original file line number Diff line number Diff line change 1
1
import { expect } from 'chai' ;
2
2
import { BSONSymbol , BSON } from '../register-bson' ;
3
3
import { bufferFromHexArray } from './tools/utils' ;
4
+ import { inspect } from 'util' ;
4
5
5
6
describe ( 'class BSONSymbol' , ( ) => {
6
7
it ( 'get _bsontype returns BSONSymbol' , ( ) => {
@@ -41,4 +42,9 @@ describe('class BSONSymbol', () => {
41
42
const result = BSON . deserialize ( bytes , { promoteValues : false } ) ;
42
43
expect ( result ) . to . have . nested . property ( 'sym._bsontype' , 'BSONSymbol' ) ;
43
44
} ) ;
45
+
46
+ it ( 'prints re-evaluatable output for BSONSymbol that contains quotes' , ( ) => {
47
+ const input = new BSONSymbol ( 'asdf"ghjk' ) ;
48
+ expect ( inspect ( input ) ) . to . equal ( String . raw `new BSONSymbol("asdf\"ghjk")` ) ;
49
+ } ) ;
44
50
} ) ;
You can’t perform that action at this time.
0 commit comments