Skip to content

Commit 31af3bd

Browse files
committed
fix(references): keep non-Latin reference labels
clean_label rejected any label without [A-Za-z0-9], so people whose names render entirely in Cyrillic (or another non-Latin script) were silently dropped from search-result references. Require a Unicode letter or digit instead; pure punctuation is still rejected. (cherry picked from commit f2d7d073cb5342d33eb315f2f5acda2b24d655e3)
1 parent a8ca5df commit 31af3bd

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

linkedin_mcp_server/scraping/link_metadata.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ def clean_label(value: str, kind: ReferenceKind) -> str | None:
358358
return None
359359
if len(value) > 80:
360360
return None
361-
if not re.search(r"[A-Za-z0-9]", value):
361+
# Require at least one letter or digit in ANY script — Cyrillic (and
362+
# other non-Latin) profile names are valid labels. [^\W_] matches a
363+
# Unicode word character that is not an underscore.
364+
if not re.search(r"[^\W_]", value):
362365
return None
363366

364367
return value

tests/test_link_metadata.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,53 @@ def test_rejects_single_character_labels(self):
257257
}
258258
]
259259

260+
def test_keeps_cyrillic_only_names(self):
261+
# Regression: a non-Latin (Cyrillic) name must survive label
262+
# cleaning. The alphanumeric guard uses a Unicode word check, not
263+
# [A-Za-z0-9], so search results from RU/BY/other locales keep their
264+
# person references instead of being dropped.
265+
references = build_references(
266+
[
267+
{
268+
"href": "https://www.linkedin.com/in/margo-yunanova/",
269+
"text": "Маргарита Юнанова",
270+
}
271+
],
272+
"search_results",
273+
)
274+
275+
assert references == [
276+
{
277+
"kind": "person",
278+
"url": "/in/margo-yunanova/",
279+
"text": "Маргарита Юнанова",
280+
"context": "search result",
281+
}
282+
]
283+
284+
def test_rejects_punctuation_only_labels_across_scripts(self):
285+
# The Unicode word guard must still reject pure punctuation/symbols
286+
# (no letter or digit in any script).
287+
references = build_references(
288+
[
289+
{
290+
"href": "https://www.linkedin.com/in/williamhgates/",
291+
"text": "—·—",
292+
"aria_label": "Bill Gates",
293+
}
294+
],
295+
"main_profile",
296+
)
297+
298+
assert references == [
299+
{
300+
"kind": "person",
301+
"url": "/in/williamhgates/",
302+
"text": "Bill Gates",
303+
"context": "top card",
304+
}
305+
]
306+
260307
def test_preserves_words_starting_with_view(self):
261308
references = build_references(
262309
[

0 commit comments

Comments
 (0)