Skip to content

Commit 3a6aaac

Browse files
Fix UUID validation
1 parent 7d67d4b commit 3a6aaac

File tree

6 files changed

+4656
-15
lines changed

6 files changed

+4656
-15
lines changed

lib/LoginHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class LoginHandler
7777
// Ignore any error
7878
}
7979

80-
if (hardwareID === null || !validator.isUUID(String(hardwareID)))
80+
if (hardwareID === null || !validator.isUUID(String(hardwareID), 'loose'))
8181
{
8282
hardwareID = UUID.random().toString();
8383
await fs.promises.writeFile(hardwareIDFile, JSON.stringify({ id0: hardwareID }));

lib/classes/EventQueueClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { InventoryLibrary } from '../enums/InventoryLibrary';
2020
import { LandStatsEvent } from '../events/LandStatsEvent';
2121

2222
import * as LLSD from '@caspertech/llsd';
23-
import type { CancelableRequest, Response } from 'got';
23+
import type { CancelableRequest, Response as GotResponse } from 'got';
2424
import got from 'got';
2525
import * as Long from 'long';
2626

@@ -30,7 +30,7 @@ export class EventQueueClient
3030
public ack?: number;
3131
public done = false;
3232

33-
private currentRequest?: CancelableRequest<Response<string>> = undefined;
33+
private currentRequest?: CancelableRequest<GotResponse<string>> = undefined;
3434
private readonly clientEvents: ClientEvents;
3535
private readonly agent: Agent;
3636

@@ -578,7 +578,7 @@ export class EventQueueClient
578578
}
579579
public async request(url: string, data: string, contentType: string): Promise<string>
580580
{
581-
let req: CancelableRequest<Response<string>> | undefined = undefined;
581+
let req: CancelableRequest<GotResponse<string>> | undefined = undefined;
582582
try
583583
{
584584
req = got.post(url, {

lib/classes/UUID.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class UUID
7676
}
7777
if (typeof obj[param] === 'string')
7878
{
79-
if (validator.isUUID(obj[param]))
79+
if (validator.isUUID(obj[param], 'loose'))
8080
{
8181
return new UUID(obj[param]);
8282
}
@@ -89,7 +89,7 @@ export class UUID
8989
const u = obj[param].UUID[0];
9090
if (typeof u === 'string')
9191
{
92-
if (validator.isUUID(u))
92+
if (validator.isUUID(u, 'loose'))
9393
{
9494
return new UUID(u);
9595
}
@@ -105,7 +105,7 @@ export class UUID
105105
public setUUID(val: string): boolean
106106
{
107107
const test = val.trim();
108-
if (validator.isUUID(test))
108+
if (validator.isUUID(test, 'loose'))
109109
{
110110
this.mUUID = test;
111111
return true;

lib/tests/uuid.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('UUID', () =>
1616
{
1717
assert.fail('Returned UUID is not a string');
1818
}
19-
if (!validator.isUUID(uuid))
19+
if (!validator.isUUID(uuid, 'loose'))
2020
{
2121
assert.fail('Returned string is not a valid UUID');
2222
}
@@ -28,7 +28,7 @@ describe('UUID', () =>
2828
{
2929
assert.fail('Returned second UUID is not a string');
3030
}
31-
if (!validator.isUUID(secondUUID))
31+
if (!validator.isUUID(secondUUID, 'loose'))
3232
{
3333
assert.fail('Second UUID is not a valid UUID');
3434
}
@@ -52,7 +52,7 @@ describe('UUID', () =>
5252
{
5353
assert.fail('Returned UUID is not a string');
5454
}
55-
if (!validator.isUUID(uuid))
55+
if (!validator.isUUID(uuid, 'loose'))
5656
{
5757
assert.fail('Returned string is not a valid UUID');
5858
}
@@ -74,7 +74,7 @@ describe('UUID', () =>
7474
{
7575
assert.fail('Returned UUID is not a string');
7676
}
77-
if (!validator.isUUID(str))
77+
if (!validator.isUUID(str, 'loose'))
7878
{
7979
assert.fail('Returned string is not a valid UUID');
8080
}
@@ -99,7 +99,7 @@ describe('UUID', () =>
9999
{
100100
assert.fail('Returned UUID is not a string');
101101
}
102-
if (!validator.isUUID(result))
102+
if (!validator.isUUID(result, 'loose'))
103103
{
104104
assert.fail('Returned string is not a valid UUID');
105105
}

0 commit comments

Comments
 (0)