diff --git a/pxr/usd/lib/usd/collectionAPI.cpp b/pxr/usd/lib/usd/collectionAPI.cpp index 6ae2b9f7db..dc8594cd23 100644 --- a/pxr/usd/lib/usd/collectionAPI.cpp +++ b/pxr/usd/lib/usd/collectionAPI.cpp @@ -144,6 +144,12 @@ UsdCollectionAPI::ApplyCollection( // Ensure that the collection name is valid. TfTokenVector tokens = SdfPath::TokenizeIdentifierAsTokens(name); + if ( tokens.empty() ) + { + TF_CODING_ERROR("Invalid collection name '%s'.", name.GetText()); + return UsdCollectionAPI(); + } + TfToken baseName = *tokens.rbegin(); if (IsSchemaPropertyBaseName(baseName)) { TF_CODING_ERROR("Invalid collection name '%s'. The base-name '%s' is a " diff --git a/pxr/usd/lib/usd/testenv/testUsdCollectionAPI.py b/pxr/usd/lib/usd/testenv/testUsdCollectionAPI.py index b2989e9342..65333aab56 100644 --- a/pxr/usd/lib/usd/testenv/testUsdCollectionAPI.py +++ b/pxr/usd/lib/usd/testenv/testUsdCollectionAPI.py @@ -52,6 +52,7 @@ def test_AuthorCollections(self): # Test an explicitOnly collection. explicitColl = Usd.CollectionAPI.ApplyCollection(testPrim, "test:Explicit:Collection", Usd.Tokens.explicitOnly) + self.assertTrue(explicitColl.HasNoIncludedPaths()) self.assertEqual(['CollectionAPI:test:Explicit:Collection'], testPrim.GetAppliedSchemas()) @@ -323,6 +324,11 @@ def test_testReadCollection(self): excludeInstanceGeomMquery, stage, predicate=Usd.TraverseInstanceProxies()) self.assertEqual(len(allIncObjects), 2) + + def test_invalidCollectionName(self): + with self.assertRaises(Exception): + explicitColl2 = Usd.CollectionAPI.ApplyCollection(testPrim, + "a:b(c)", Usd.Tokens.explicitOnly) def test_invalidCollections(self): invalidCollectionNames = ["invalidExpansionRule",