{"record":{"id":"e76462b1e3ad4ab3","repo":"phacility/phabricator","slug":"version-name-s-is-not-valid-version-names-may","errorCode":null,"errorMessage":"Version name \"%s\" is not valid: version names may only contain latin letters, digits, periods, and hyphens.","messagePattern":"Version name \"(.+?)\" is not valid: version names may only contain latin letters, digits, periods, and hyphens\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/packages/storage/PhabricatorPackagesVersion.php","lineNumber":81,"sourceCode":"    if (!$length) {\n      throw new Exception(\n        pht(\n          'Version name \"%s\" is not valid: version names are required.',\n          $value));\n    }\n\n    $max_length = 64;\n    if ($length > $max_length) {\n      throw new Exception(\n        pht(\n          'Version name \"%s\" is not valid: version names must not be '.\n          'more than %s characters long.',\n          $value,\n          new PhutilNumber($max_length)));\n    }\n\n    if (!preg_match('/^[A-Za-z0-9.-]+\\z/', $value)) {\n      throw new Exception(\n        pht(\n          'Version name \"%s\" is not valid: version names may only contain '.\n          'latin letters, digits, periods, and hyphens.',\n          $value));\n    }\n\n    if (preg_match('/^[.-]|[.-]$/', $value)) {\n      throw new Exception(\n        pht(\n          'Version name \"%s\" is not valid: version names may not start or '.\n          'end with a period or hyphen.',\n          $value));\n    }\n  }\n\n\n/* -(  PhabricatorSubscribableInterface  )----------------------------------- */\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/packages/storage/PhabricatorPackagesVersion.php#L63-L99","documentation":"Thrown by PhabricatorPackagesVersion::assertValidVersionName() when the version name contains characters outside /^[A-Za-z0-9.-]+\\z/. Only latin letters, digits, periods, and hyphens are allowed; spaces, underscores, plus signs (semver build metadata), slashes, and multibyte characters are rejected.","triggerScenarios":"Submitting a version name such as '1.0.0-beta+1' (rejected '+'), 'v1.0 (stable)' (spaces/parens), 'release_2' (underscore), or a unicode tag like 'verze 1' through the version editor or import path.","commonSituations":"Importing tags from VCS tools that allow arbitrary ref characters; semver strings with '+' build metadata; localized version labels; scripts converting spaces to underscores instead of hyphens.","solutions":["Sanitize the name: keep only [A-Za-z0-9.-], mapping underscores and spaces to hyphens.","Drop semver '+' build metadata from the name and record it elsewhere (e.g. description).","Validate against ^[A-Za-z0-9.-]+$ before applying version transactions."],"exampleFix":"// before\n$name = '1.0.0-beta+1';\n\n// after\n$name = preg_replace('/[^A-Za-z0-9.-]+/', '-', '1.0.0-beta+1');\n// $name is now '1.0.0-beta-1-'\n$name = trim($name, '.-');\nPhabricatorPackagesVersion::assertValidVersionName($name);","handlingStrategy":"validation","validationCode":"$name = preg_replace('/[^A-Za-z0-9.-]+/', '-', $raw_name);\n$name = trim($name, '.-');\nif (!preg_match('/^[A-Za-z0-9.-]+\\z/', $name)) {\n  // reject - cannot be represented\n}\nPhabricatorPackagesVersion::assertValidVersionName($name);","typeGuard":"function is_valid_version_charset($name) {\n  return is_string($name)\n    && preg_match('/^[A-Za-z0-9.-]+\\z/', $name) === 1;\n}","tryCatchPattern":"try {\n  PhabricatorPackagesVersion::assertValidVersionName($name);\n} catch (Exception $ex) {\n  $errors[] = $ex->getMessage();\n}","preventionTips":["Strip semver '+' build metadata from tags before importing them as version names.","Normalize spaces and underscores to hyphens in one sanitization step.","Reject VCS ref names containing slashes early (they indicate a branch path, not a version)."],"tags":["phabricator","packages","version","validation","sanitization"],"backgroundTag":"identifier-format-validation","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}