diff --git a/packages/consts/src/regexs.ts b/packages/consts/src/regexs.ts index 627e1ad3..fcc8d8ed 100644 --- a/packages/consts/src/regexs.ts +++ b/packages/consts/src/regexs.ts @@ -160,5 +160,4 @@ export const CONTACT_LINK_REGEX = /^(mailto|tel|sms):.*$/i; * because we have user objects with that in database. * @type {RegExp} */ -// TODO: @fnesveda [2022-08-15] revert to stricter regex /^[a-zA-Z0-9]{17}$/ once we properly delete user yZtyxMUADJHyInTIdl -export const APIFY_ID_REGEX = /[a-zA-Z0-9]{17}/; +export const APIFY_ID_REGEX = /^[a-zA-Z0-9]{17}$/; diff --git a/test/consts.test.ts b/test/consts.test.ts index 0d182494..8d29a4d2 100644 --- a/test/consts.test.ts +++ b/test/consts.test.ts @@ -58,14 +58,23 @@ describe('consts', () => { const testingStrings = { valid: ['S64xo2hmHBFHbqZQq', 'Z7rgePnfc04QHshc2'], invalid: [ - // Invalid length + // Too short 'Z7rgePnfc04QHshc', + // Too long + 'Z7rgePnfc04QHshc2X', + 'yZtyxMUADJHyInTIdl', // Invalid chars '_7rgePnfc04QHshc2', '-7rgePnfc04QHshc2', '~7rgePnfc04QHshc2', '}7rgePnfc04QHshc2', '(7rgePnfc04QHshc2', + // Valid 17-char ID embedded in a larger string (must be rejected by the anchored regex) + ' S64xo2hmHBFHbqZQq', + 'S64xo2hmHBFHbqZQq ', + 'xS64xo2hmHBFHbqZQqx', + // Empty string + '', ], }; testingStrings.valid.forEach((str) => {