@@ -285,6 +285,26 @@ describe('AmplitudeClient', function () {
285285 amplitude . _getUrlParams . restore ( ) ;
286286 } ) ;
287287
288+ it ( 'should reject invalid device ids that contain periods' , function ( ) {
289+ const spyErrorWarning = sinon . spy ( utils . log , 'error' ) ;
290+ const badDeviceId = 'bad.device.id' ;
291+ amplitude . init ( apiKey , null , { deviceId : badDeviceId } ) ;
292+
293+ assert . isTrue (
294+ spyErrorWarning . calledWith (
295+ `Device IDs may not contain '.' characters. Value will be ignored: "${ badDeviceId } "` ,
296+ ) ,
297+ ) ;
298+ assert . isTrue (
299+ spyErrorWarning . calledWith (
300+ `Invalid device ID rejected. Randomly generated UUID will be used instead of "${ badDeviceId } "` ,
301+ ) ,
302+ ) ;
303+ assert . notEqual ( amplitude . options . deviceId , badDeviceId ) ;
304+
305+ spyErrorWarning . restore ( ) ;
306+ } ) ;
307+
288308 it ( 'should load device id from the cookie' , function ( ) {
289309 // deviceId and sequenceNumber not set, init should load value from localStorage
290310 var cookieData = {
@@ -1048,6 +1068,21 @@ describe('AmplitudeClient', function () {
10481068 var stored = amplitude . _metadataStorage . load ( ) ;
10491069 assert . propertyVal ( stored , 'deviceId' , 'deviceId' ) ;
10501070 } ) ;
1071+
1072+ it ( 'should not take periods in deviceId' , function ( ) {
1073+ const spyErrorWarning = sinon . spy ( utils . log , 'error' ) ;
1074+ amplitude . init ( apiKey , null , { deviceId : 'fakeDeviceId' } ) ;
1075+ const badDeviceId = 'bad.device.id' ;
1076+ amplitude . setDeviceId ( badDeviceId ) ;
1077+ var stored = amplitude . _metadataStorage . load ( ) ;
1078+ assert . propertyVal ( stored , 'deviceId' , 'fakeDeviceId' ) ;
1079+ assert . isTrue (
1080+ spyErrorWarning . calledWith (
1081+ `Device IDs may not contain '.' characters. Value will be ignored: "${ badDeviceId } "` ,
1082+ ) ,
1083+ ) ;
1084+ spyErrorWarning . restore ( ) ;
1085+ } ) ;
10511086 } ) ;
10521087
10531088 describe ( 'resetSessionId' , function ( ) {
0 commit comments