Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pinecone/utils/user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
def _build_source_tag_field(source_tag):
# normalize source tag
# 1. Lowercase
# 2. Limit charset to [a-z0-9_ ]
# 2. Limit charset to [a-z0-9_ :]
# 3. Trim left/right whitespace
# 4. Condense multiple spaces to one, and replace with underscore
tag = source_tag.lower()
tag = re.sub(r'[^a-z0-9_ ]', '', tag)
tag = re.sub(r'[^a-z0-9_ :]', '', tag)
tag = tag.strip()
tag = "_".join(tag.split())
return f"{SOURCE_TAG}={tag}"
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/utils/test_user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def test_source_tag_is_normalized(self):
useragent = get_user_agent(config)
assert re.search(r"source_tag=my_source_tag_123", useragent) is not None

config = ConfigBuilder.build(api_key="my-api-key", host="https://my-controller-host", source_tag="colon:allowed")
useragent = get_user_agent(config)
assert re.search(r"source_tag=colon:allowed", useragent) is not None

def test_user_agent_grpc(self):
config = ConfigBuilder.build(api_key="my-api-key", host="https://my-controller-host")
useragent = get_user_agent_grpc(config)
Expand Down