{"record":{"id":"2ef4be7fc43ad918","repo":"hyperledger/fabric","slug":"collection-name-s-not-allowed-a-valid-collectio-2ef4be","errorCode":null,"errorMessage":"collection-name: %s not allowed. A valid collection name follows the pattern: %s","messagePattern":"collection-name: (.+?) not allowed\\. A valid collection name follows the pattern: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v13/lscc_validation_logic.go","lineNumber":210,"sourceCode":"\n\tif err := checkForMissingCollections(newCollectionsMap, oldCollectionConfigs); err != nil {\n\t\treturn err\n\t}\n\n\tif err := checkForModifiedCollectionsBTL(newCollectionsMap, oldCollectionConfigs); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc validateCollectionName(collectionName string) error {\n\tif collectionName == \"\" {\n\t\treturn fmt.Errorf(\"empty collection-name is not allowed\")\n\t}\n\tmatch := validCollectionNameRegex.FindString(collectionName)\n\tif len(match) != len(collectionName) {\n\t\treturn fmt.Errorf(\"collection-name: %s not allowed. A valid collection name follows the pattern: %s\",\n\t\t\tcollectionName, AllowedCharsCollectionName)\n\t}\n\treturn nil\n}\n\n// validateRWSetAndCollection performs validation of the rwset\n// of an LSCC deploy operation and then it validates any collection\n// configuration\nfunc (vscc *Validator) validateRWSetAndCollection(\n\tlsccrwset *kvrwset.KVRWSet,\n\tcdRWSet *ccprovider.ChaincodeData,\n\tlsccArgs [][]byte,\n\tlsccFunc string,\n\tac vc.Capabilities,\n\tchannelName string,\n) commonerrors.TxValidationError {\n\t/********************************************/\n\t/* security check 0.a - validation of rwset */","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v13/lscc_validation_logic.go#L192-L228","documentation":"After the empty-name check, validateCollectionName applies validCollectionNameRegex to the collection name and requires the whole string to match. Names may only contain the characters described by AllowedCharsCollectionName (alphanumerics plus a limited set of symbols); any name containing disallowed characters is rejected with the pattern requirement spelled out.","triggerScenarios":"Submitting a collection config whose name contains characters outside the allowed set, e.g. spaces, slashes, unicode, 'coll#1' or 'my collection', during chaincode definition or upgrade.","commonSituations":"Using org/channel names or file paths (with slashes) as collection names; spaces instead of camelCase or hyphens; localized/unicode names; names copied with trailing whitespace or newline.","solutions":["Rename the collection using only allowed characters (typically alphanumeric plus '-', '_'); e.g. use 'coll1' not 'coll 1'","Trim whitespace and validate the name against the documented pattern before submission","Keep a shared naming convention (lowercase alphanumerics and hyphens) across teams and tooling"],"exampleFix":"// before\n{\"name\": \"my collection #1\"}\n// after\n{\"name\": \"my-collection-1\"}","handlingStrategy":"validation","validationCode":"const ALLOWED = /^[a-zA-Z0-9_-]+$/; // mirror AllowedCharsCollectionName\nfunction validateCollectionName(name) {\n  if (!ALLOWED.test(name)) {\n    throw new Error(`collection name '${name}' contains disallowed characters`);\n  }\n}","typeGuard":"function isValidCollectionName(name) {\n  return typeof name === 'string' && /^[a-zA-Z0-9_-]+$/.test(name);\n}","tryCatchPattern":"try {\n  await contract.submitTransaction('DeployChaincode', ...args);\n} catch (err) {\n  if (String(err).includes('not allowed. A valid collection name')) {\n    // rename collections to match the allowed pattern\n  }\n  throw err;\n}","preventionTips":["Restrict names to alphanumerics, hyphens, and underscores by convention","Trim whitespace/newlines from names read from files or env vars","Add a regex test to any tooling that generates collection configs"],"tags":["hyperledger-fabric","private-data","collection-name","regex","validation"],"backgroundTag":"invalid-collection-name","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}