File tree Expand file tree Collapse file tree 4 files changed +16
-2
lines changed Expand file tree Collapse file tree 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 {
6262
6363 inspect ( ) : string {
6464 const codeJson = this . toJSON ( ) ;
65- return `new Code(" ${ String ( codeJson . code ) } " ${
65+ return `new Code(${ JSON . stringify ( String ( codeJson . code ) ) } ${
6666 codeJson . scope != null ? `, ${ JSON . stringify ( codeJson . scope ) } ` : ''
6767 } )`;
6868 }
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export class BSONSymbol extends BSONValue {
3434 }
3535
3636 inspect ( ) : string {
37- return `new BSONSymbol(" ${ this . value } " )` ;
37+ return `new BSONSymbol(${ JSON . stringify ( this . value ) } )` ;
3838 }
3939
4040 toJSON ( ) : string {
Original file line number Diff line number Diff line change 11import { expect } from 'chai' ;
22import * as BSON from '../register-bson' ;
3+ import { inspect } from 'util' ;
34
45describe ( 'class Code' , ( ) => {
56 it ( 'defines a nodejs inspect method' , ( ) => {
@@ -8,6 +9,13 @@ describe('class Code', () => {
89 . that . is . a ( 'function' ) ;
910 } ) ;
1011
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+
1119 describe ( 'new Code()' , ( ) => {
1220 it ( 'defines a code property that is a string' , ( ) => {
1321 const codeStringInput = new BSON . Code ( 'function a(){}' ) ;
Original file line number Diff line number Diff line change 11import { expect } from 'chai' ;
22import { BSONSymbol , BSON } from '../register-bson' ;
33import { bufferFromHexArray } from './tools/utils' ;
4+ import { inspect } from 'util' ;
45
56describe ( 'class BSONSymbol' , ( ) => {
67 it ( 'get _bsontype returns BSONSymbol' , ( ) => {
@@ -41,4 +42,9 @@ describe('class BSONSymbol', () => {
4142 const result = BSON . deserialize ( bytes , { promoteValues : false } ) ;
4243 expect ( result ) . to . have . nested . property ( 'sym._bsontype' , 'BSONSymbol' ) ;
4344 } ) ;
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+ } ) ;
4450} ) ;
You can’t perform that action at this time.
0 commit comments