Skip to content

Commit ce61412

Browse files
[cuegui] Fix layer tags validation to allow dashes and underscores (#2120)
**Link the Issue(s) this Pull Request is related to.** - #2117 **Summarize your change.** - The TagsWidget.get_tags() method used isalnum() to filter tags, which rejected any tag containing dashes (e.g., "test-layer-tag"). This caused the layer properties dialog to fail with "no tag selected" error. - Replace isalnum() with a new _is_valid_tag() method that uses regex to allow alphanumeric characters, dashes, and underscores in tag names.
1 parent 3599a1e commit ce61412

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

cuegui/cuegui/TagsWidget.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,22 @@ def get_tags(self):
128128
tags = re.split(r'[\s,|]+', tags)
129129
else:
130130
tags = [str(t.text()) for t in self.standard_tags.checkedBoxes()]
131-
return [tag.strip() for tag in tags if tag.strip().isalnum()]
131+
return [tag.strip() for tag in tags if self._is_valid_tag(tag.strip())]
132+
133+
@staticmethod
134+
def _is_valid_tag(tag):
135+
"""
136+
Check if a tag is valid. Valid tags contain only alphanumeric characters,
137+
dashes, and underscores, and must not be empty.
138+
139+
@param tag: The tag to validate
140+
@type tag: str
141+
@return: Whether the tag is valid
142+
@rtype: bool
143+
"""
144+
if not tag:
145+
return False
146+
return bool(re.match(r'^[a-zA-Z0-9_-]+$', tag))
132147

133148
def is_custom_enabled(self):
134149
"""

cuegui/tests/test_tags_widget.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright Contributors to the OpenCue Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
"""Tests for cuegui.TagsWidget."""
17+
18+
19+
import unittest
20+
21+
import cuegui.TagsWidget
22+
23+
24+
class IsValidTagTests(unittest.TestCase):
25+
"""Tests for TagsWidget._is_valid_tag method."""
26+
27+
def test_alphanumeric_tag(self):
28+
"""Standard alphanumeric tags should be valid."""
29+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('general'))
30+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag123'))
31+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('UPPERCASE'))
32+
33+
def test_tag_with_dashes(self):
34+
"""Tags containing dashes should be valid."""
35+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('test-layer-tag'))
36+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('my-tag'))
37+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('a-b-c'))
38+
39+
def test_tag_with_underscores(self):
40+
"""Tags containing underscores should be valid."""
41+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('my_tag'))
42+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('test_layer_tag'))
43+
44+
def test_mixed_characters(self):
45+
"""Tags with mixed valid characters should be valid."""
46+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('MixedCase-123'))
47+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag_with-both'))
48+
self.assertTrue(cuegui.TagsWidget.TagsWidget._is_valid_tag('GPU-v100_render'))
49+
50+
def test_empty_tag(self):
51+
"""Empty tags should be invalid."""
52+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag(''))
53+
54+
def test_tag_with_spaces(self):
55+
"""Tags containing spaces should be invalid."""
56+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag with space'))
57+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag(' leading'))
58+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('trailing '))
59+
60+
def test_tag_with_special_characters(self):
61+
"""Tags containing special characters should be invalid."""
62+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag@special'))
63+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag!'))
64+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag#hash'))
65+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag.dot'))
66+
self.assertFalse(cuegui.TagsWidget.TagsWidget._is_valid_tag('tag/slash'))
67+
68+
69+
if __name__ == '__main__':
70+
unittest.main()

0 commit comments

Comments
 (0)