diff --git a/lib/pbxProject.js b/lib/pbxProject.js index 07fc062..f2f5a21 100644 --- a/lib/pbxProject.js +++ b/lib/pbxProject.js @@ -152,7 +152,9 @@ PBXProject.prototype.generateUuid = function () { .substr(0, 24) .toUpperCase(); - if (this.allUuids().indexOf(id) >= 0) { + // The parser reads an all-digit value with no trailing comment as a number, + // so an id made only of digits would not survive a write and a parse. + if (/^[0-9]+$/.test(id) || this.allUuids().indexOf(id) >= 0) { return this.generateUuid(); } else { return id; diff --git a/test/pbxProject.js b/test/pbxProject.js index 2b62a24..99545d7 100644 --- a/test/pbxProject.js +++ b/test/pbxProject.js @@ -23,6 +23,7 @@ const assert = require('node:assert'); const PBXProject = require('../lib/pbxProject'); const buildConfig = require('./fixtures/buildFiles'); const jsonProject = require('./fixtures/full-project'); +const crypto = require('crypto'); const fs = require('fs'); describe('PBXProject', () => { @@ -143,6 +144,17 @@ describe('PBXProject', () => { assert.ok(uHex.test(newUUID)); }); + it('should not return an id made only of digits', (t) => { + const project = new PBXProject('.'); + const uuids = ['12345678-9012-4345-8678-901234567890', '0a1b2c3d-4e5f-4a6b-8c7d-8e9f0a1b2c3d']; + const randomUUID = t.mock.method(crypto, 'randomUUID', () => uuids.shift()); + + project.hash = buildConfig; + const newUUID = project.generateUuid(); + + assert.equal(newUUID, '0A1B2C3D4E5F4A6B8C7D8E9F'); + assert.equal(randomUUID.mock.callCount(), 2); + }); }); const bcpbx = 'test/parser/projects/build-config.pbxproj';