fix: [BUG] `#` character accumulation in markdown frontmatter tags pr… · basicmachines-co/basic-memory@6c19c9e · GitHub
Skip to content

Commit 6c19c9e

Browse files
fix: [BUG] # character accumulation in markdown frontmatter tags prop (#79)
1 parent 9bff1f7 commit 6c19c9e

3 files changed

Lines changed: 62 additions & 3 deletions

File tree

src/basic_memory/services/entity_service.py

Lines changed: 1 addition & 1 deletion

src/basic_memory/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,23 @@ def parse_tags(tags: Union[List[str], str, None]) -> List[str]:
138138
139139
Returns:
140140
A list of tag strings, or an empty list if no tags
141+
142+
Note:
143+
This function strips leading '#' characters from tags to prevent
144+
their accumulation when tags are processed multiple times.
141145
"""
142146
if tags is None:
143147
return []
144148

149+
# Process list of tags
145150
if isinstance(tags, list):
146-
return tags
151+
# First strip whitespace, then strip leading '#' characters to prevent accumulation
152+
return [tag.strip().lstrip('#') for tag in tags if tag and tag.strip()]
147153

154+
# Process comma-separated string of tags
148155
if isinstance(tags, str):
149-
return [tag.strip() for tag in tags.split(",") if tag.strip()]
156+
# Split by comma, strip whitespace, then strip leading '#' characters
157+
return [tag.strip().lstrip('#') for tag in tags.split(",") if tag and tag.strip()]
150158

151159
# For any other type, try to convert to string and parse
152160
try: # pragma: no cover

tests/utils/test_parse_tags.py

Lines changed: 51 additions & 0 deletions

0 commit comments

Comments
 (0)