@@ -107,6 +107,39 @@ def test_multiple_cms_component_tags_error(self):
107107 with self .assertRaises (TemplateSyntaxError ):
108108 Template (invalid_template )
109109
110+ def test_cms_component_invalid_identifier (self ):
111+ # Test that cms_component tag raises ValueError for invalid identifiers
112+ from django .template import Context
113+ from djangocms_frontend .templatetags .cms_component import cms_component
114+
115+ context = Context ({"_cms_components" : {"cms_component" : []}})
116+
117+ # Valid identifier should work
118+ cms_component (context , "valid_name" )
119+ self .assertEqual (len (context ["_cms_components" ]["cms_component" ]), 1 )
120+
121+ # Non-string identifiers should raise ValueError
122+ with self .assertRaises (ValueError ) as cm :
123+ cms_component (context , 123 )
124+ self .assertIn ("component name must be a string." , str (cm .exception ))
125+
126+ # Invalid identifiers should raise ValueError
127+ with self .assertRaises (ValueError ) as cm :
128+ cms_component (context , "invalid-name" )
129+ self .assertIn ("valid Python identifier" , str (cm .exception ))
130+
131+ with self .assertRaises (ValueError ) as cm :
132+ cms_component (context , "123invalid" )
133+ self .assertIn ("valid Python identifier" , str (cm .exception ))
134+
135+ with self .assertRaises (ValueError ) as cm :
136+ cms_component (context , "invalid name" )
137+ self .assertIn ("valid Python identifier" , str (cm .exception ))
138+
139+ with self .assertRaises (ValueError ) as cm :
140+ cms_component (context , "" )
141+ self .assertIn ("valid Python identifier" , str (cm .exception ))
142+
110143 def test_component_folder_selection (self ):
111144 from djangocms_frontend .component_pool import find_cms_component_templates
112145
0 commit comments