File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5858 "google-gax" : " ^0.7.0" ,
5959 "google-proto-files" : " ^0.8.0" ,
6060 "is" : " ^3.0.1" ,
61+ "is-circular" : " ^1.0.1" ,
6162 "string-format-obj" : " ^1.0.0"
6263 },
6364 "devDependencies" : {
Original file line number Diff line number Diff line change 2323var common = require ( '@google-cloud/common' ) ;
2424var extend = require ( 'extend' ) ;
2525var is = require ( 'is' ) ;
26+ var isCircular = require ( 'is-circular' ) ;
2627
2728/**
2829 * Create an entry object to define new data to insert into a log.
@@ -122,6 +123,10 @@ Entry.fromApiResponse_ = function(entry) {
122123 * @private
123124 */
124125Entry . prototype . toJSON = function ( ) {
126+ if ( is . object ( this . data ) && isCircular ( this . data ) ) {
127+ throw new Error ( 'The JSON data for this entry has a circular reference.' ) ;
128+ }
129+
125130 var entry = extend ( true , { } , this ) ;
126131
127132 var whitelist = [
Original file line number Diff line number Diff line change @@ -186,6 +186,15 @@ describe('Entry', function() {
186186 assert . strictEqual ( json . jsonPayload , converted ) ;
187187 } ) ;
188188
189+ it ( 'should throw with a struct with a circular reference' , function ( ) {
190+ entry . data = { val : true } ;
191+ entry . data . data = entry . data ;
192+
193+ assert . throws ( function ( ) {
194+ entry . toJSON ( ) ;
195+ } , / T h e J S O N d a t a f o r t h i s e n t r y h a s a c i r c u l a r r e f e r e n c e \. / ) ;
196+ } ) ;
197+
189198 it ( 'should assign string data as textPayload' , function ( ) {
190199 entry . data = 'string' ;
191200 var json = entry . toJSON ( ) ;
You can’t perform that action at this time.
0 commit comments