Skip to content

Commit 05c59fe

Browse files
committed
1 parent 2e35366 commit 05c59fe

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

src/Utils-spec.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22

33
module Exceptionless {
44
describe('Utils', () => {
5-
it('should parse version from url', () => {
6-
expect(Utils.parseVersion('https://code.jquery.com/jquery-2.1.3.js')).toBe('2.1.3');
7-
expect(Utils.parseVersion('//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css')).toBe('3.3.4');
8-
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css')).toBe('2.0');
9-
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js')).toBe('0.3.0');
10-
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.1.0-X.10/angular-google-maps.min.js')).toBe('2.1.0-X.10');
11-
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/2.1.8-M1/swagger-ui.min.js')).toBe('2.1.8-M1');
12-
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/BLAH/BLAH.min.js')).toBe(null);
13-
});
5+
it('should stringify circular reference', () => {
6+
var afoo:any = { a: 'foo' };
7+
afoo.b = afoo;
8+
9+
expect(Utils.stringify(afoo)).toBe('{"a":"foo"}');
10+
expect(Utils.stringify({ one: afoo, two: afoo })).toBe('{"one":{"a":"foo"}}');
11+
});
12+
13+
it('should parse version from url', () => {
14+
expect(Utils.parseVersion('https://code.jquery.com/jquery-2.1.3.js')).toBe('2.1.3');
15+
expect(Utils.parseVersion('//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css')).toBe('3.3.4');
16+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css')).toBe('2.0');
17+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js')).toBe('0.3.0');
18+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.1.0-X.10/angular-google-maps.min.js')).toBe('2.1.0-X.10');
19+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/2.1.8-M1/swagger-ui.min.js')).toBe('2.1.8-M1');
20+
expect(Utils.parseVersion('https://cdnjs.cloudflare.com/BLAH/BLAH.min.js')).toBe(null);
21+
});
1422
});
1523
}

src/Utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,22 @@ module Exceptionless {
7979
public static randomNumber(): number {
8080
return Math.floor(Math.random() * 9007199254740992);
8181
}
82+
83+
public static stringify(data:any): string {
84+
var cache = [];
85+
86+
return JSON.stringify(data, function(key, value) {
87+
if (typeof value === 'object' && value !== null) {
88+
if (cache.indexOf(value) !== -1) {
89+
// Circular reference found, discard key
90+
return;
91+
}
92+
93+
cache.push(value);
94+
}
95+
96+
return value;
97+
});
98+
}
8299
}
83100
}

src/submission/DefaultSubmissionClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ module Exceptionless {
44
export class DefaultSubmissionClient implements ISubmissionClient {
55
public submit(events:IEvent[], config:Configuration): Promise<SubmissionResponse> {
66
var url = config.serverUrl + '/api/v2/events?access_token=' + encodeURIComponent(config.apiKey);
7-
return this.sendRequest('POST', url, JSON.stringify(events)).then(
7+
return this.sendRequest('POST', url, Utils.stringify(events)).then(
88
xhr => { return new SubmissionResponse(xhr.status, this.getResponseMessage(xhr)); },
99
xhr => { return new SubmissionResponse(xhr.status || 500, this.getResponseMessage(xhr)); }
1010
);
1111
}
1212

1313
public submitDescription(referenceId:string, description:IUserDescription, config:Configuration): Promise<SubmissionResponse> {
1414
var url = config.serverUrl + '/api/v2/events/by-ref/' + encodeURIComponent(referenceId) + '/user-description?access_token=' + encodeURIComponent(config.apiKey);
15-
return this.sendRequest('POST', url, JSON.stringify(description)).then(
15+
return this.sendRequest('POST', url, Utils.stringify(description)).then(
1616
xhr => { return new SubmissionResponse(xhr.status, this.getResponseMessage(xhr)); },
1717
xhr => { return new SubmissionResponse(xhr.status || 500, this.getResponseMessage(xhr)); }
1818
);

0 commit comments

Comments
 (0)