Skip to content

Commit 6b16f21

Browse files
committed
fix potential errors parsing the trailing month
1 parent cd03590 commit 6b16f21

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bib_lookup/_bib.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ def __normalize_fields(self, check_fields: bool = False) -> None:
134134
# remove redundant curly braces and commas
135135
v = str(v).strip(" ,") # DO NOT strip "{}"
136136
self.__double_braces_flags[k] = False
137-
braces_count = 0
137+
braces_count = 1
138138
# exclude the case where the leading and trailing words are enclosed by braces
139139
# e.g. "{IDH1} and {IDH2} mutations in postoperative diffuse glioma-associated {epilepsy}"
140140
tmp_v = re.sub("\\{[^\\{\\}]*\\}", "", v).strip()
141+
if not re.findall("\\w+", tmp_v):
142+
# exclude the case {{...}}
143+
tmp_v = v
141144
while (
142145
all([tmp_v.startswith("{"), tmp_v.endswith("}")])
143146
or all([v.startswith('"'), v.endswith('"')])
@@ -146,6 +149,9 @@ def __normalize_fields(self, check_fields: bool = False) -> None:
146149
v = v[1:-1]
147150
braces_count += 1
148151
tmp_v = re.sub("\\{[^\\{\\}]*\\}", "", v).strip()
152+
if not re.findall("\\w+", tmp_v):
153+
# exclude the case {{...}}
154+
tmp_v = v
149155
if braces_count >= 2:
150156
self.__double_braces_flags[k] = True
151157
# convert month to number if applicable

bib_lookup/bib_lookup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ def _to_bib_item(
817817
field_dict = {k.lower(): v.strip(", ") for k, v in field_dict.items() if k.lower() not in _ignore_fields}
818818
# take off at most one pair of double quotes or single quotes or braces at the beginning and the end of the value
819819
for k, v in field_dict.items():
820+
# if the field ends with a } but without a leading {, remove the trailing }
821+
# this resolves the issue with fetched content that ends with, for example, "month=jun }"
822+
if field_dict[k].endswith("}") and not field_dict[k].startswith("{"):
823+
field_dict[k] = field_dict[k][:-1].strip()
820824
tmp_v = re.sub("\\{[^\\{\\}]*\\}", "", v).strip()
821825
if v.startswith('"') and v.endswith('"'):
822826
field_dict[k] = v[1:-1]

0 commit comments

Comments
 (0)