File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ]
You can’t perform that action at this time.
0 commit comments