Skip to content

ArXiv search response parsing uses fragile regex on XML #154

Open

Description

@owe90

ArXiv search response parsing uses fragile regex on XML

Severity: Low
File: backend/app/services/search_service.py:265

The _parse_arxiv_response method parses XML using regex patterns to extract <title>, <abstract>, and other fields. This approach breaks if ArXiv changes XML structure, adds namespaces, or includes CDATA sections.

entries = re.findall(r'<entry>(.*?)</entry>', xml_text, re.DOTALL)

for entry in entries:
    title_match = re.search(r'<title>(.*?)</title>', entry, re.DOTALL)
    abstract_match = re.search(r'<summary>(.*?)</summary>', entry, re.DOTALL)
    published_match = re.search(r'<published>(.*?)</published>', entry)
    id_match = re.search(r'<id>(.*?)</id>', entry)

Why it matters

ArXiv API changes or malformed responses cause silent failures or incorrect parsing. A proper XML parser would handle namespaces, encoding, and structure changes gracefully.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions