Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 6956da8

Browse files
authored
stringify sourceContext before concat (#265)
1 parent e7f15f5 commit 6956da8

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/agent/debuglet.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,8 @@ Debuglet.createDebuggee =
290290
desc += ' description:' + description;
291291
}
292292

293-
var uniquifier =
294-
desc + version + uid + sourceContext + JSON.stringify(labels);
295-
uniquifier = crypto.createHash('sha1').update(uniquifier).digest('hex');
293+
var uniquifier = Debuglet._createUniquifier(desc, version, uid, sourceContext,
294+
labels);
296295

297296
var statusMessage =
298297
errorMessage ?
@@ -736,3 +735,10 @@ Debuglet._delimit = function(source, delim) {
736735
}
737736
return dest;
738737
};
738+
739+
Debuglet._createUniquifier = function (desc, version, uid, sourceContext,
740+
labels) {
741+
var uniquifier = desc + version + uid + JSON.stringify(sourceContext) +
742+
JSON.stringify(labels);
743+
return crypto.createHash('sha1').update(uniquifier).digest('hex');
744+
};

test/test-debuglet.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,4 +793,43 @@ describe('Debuglet', function() {
793793
});
794794
});
795795

796+
describe('_createUniquifier', function () {
797+
it('should create a unique string', function () {
798+
var fn = Debuglet._createUniquifier;
799+
800+
var desc = 'description';
801+
var version = 'version';
802+
var uid = 'uid';
803+
var sourceContext = {
804+
git: 'something'
805+
};
806+
var labels = {
807+
key: 'value'
808+
};
809+
810+
var u1 = fn(desc, version, uid, sourceContext, labels);
811+
812+
assert.strictEqual(fn(desc, version, uid, sourceContext, labels), u1);
813+
814+
assert.notStrictEqual(
815+
fn('foo', version, uid, sourceContext, labels),
816+
u1,
817+
'changing the description should change the result');
818+
assert.notStrictEqual(
819+
fn(desc, '1.2', uid, sourceContext, labels),
820+
u1,
821+
'changing the version should change the result');
822+
assert.notStrictEqual(
823+
fn(desc, version, '5', sourceContext, labels), u1,
824+
'changing the description should change the result');
825+
assert.notStrictEqual(
826+
fn(desc, version, uid, { git: 'blah' }, labels),
827+
u1,
828+
'changing the sourceContext should change the result');
829+
assert.notStrictEqual(
830+
fn(desc, version, uid, sourceContext, { key1: 'value2' }),
831+
u1,
832+
'changing the labels should change the result');
833+
});
834+
});
796835
});

0 commit comments

Comments
 (0)