Skip to content
Open
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 backend/app/storage/paper_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_paper(paper_id: str) -> Optional[Dict[str, Any]]:
path = os.path.join(PAPERS_DIR, paper_id, "meta.json")
if not os.path.isfile(path):
return None
with open(path) as f:
with open(path, encoding="utf-8") as f:
return _normalize_record(json.load(f))


Expand All @@ -109,7 +109,7 @@ def list_papers() -> List[Dict[str, Any]]:
meta = os.path.join(PAPERS_DIR, name, "meta.json")
if os.path.isfile(meta):
try:
with open(meta) as f:
with open(meta, encoding="utf-8") as f:
results.append(_normalize_record(json.load(f)))
except Exception:
pass
Expand Down
51 changes: 51 additions & 0 deletions backend/tests/test_pr_03_paper_storage_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Test that paper_storage.py get_paper/list_papers handle non-ASCII content."""

import json
import os
from unittest import mock

import pytest


@pytest.fixture
def tmp_papers_dir(tmp_path):
d = tmp_path / "papers"
d.mkdir()
return str(d)


def test_get_paper_non_ascii(tmp_papers_dir):
"""Create a paper with Chinese title/authors and verify get_paper returns it intact."""
with mock.patch("app.storage.paper_storage.PAPERS_DIR", tmp_papers_dir):
from app.storage import paper_storage

data = {
"title": "基于深度学习的自然语言处理综述",
"authors": ["张三", "李四"],
"paperType": "survey",
"targetVenue": "ACL",
}
record = paper_storage.create_paper(data)
paper_id = record["id"]

fetched = paper_storage.get_paper(paper_id)
assert fetched is not None
assert fetched["title"] == "基于深度学习的自然语言处理综述"
assert fetched["authors"] == ["张三", "李四"]


def test_list_papers_non_ascii(tmp_papers_dir):
"""Verify list_papers returns non-ASCII titles correctly."""
with mock.patch("app.storage.paper_storage.PAPERS_DIR", tmp_papers_dir):
from app.storage import paper_storage

paper_storage.create_paper({"title": "Premier article"})
paper_storage.create_paper({"title": "第二篇论文"})
paper_storage.create_paper({"title": "Übung macht den Meister"})

papers = paper_storage.list_papers()
assert len(papers) == 3
titles = {p["title"] for p in papers}
assert "Premier article" in titles
assert "第二篇论文" in titles
assert "Übung macht den Meister" in titles