Checks if caption is not None before normalization (#1475)

This commit is contained in:
MiguelX413 2022-04-18 07:49:34 +00:00 committed by GitHub
parent 218d88fc6d
commit 0704602e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -365,10 +365,16 @@ class Post:
@property @property
def caption(self) -> Optional[str]: def caption(self) -> Optional[str]:
"""Caption.""" """Caption."""
def _normalize(string: Optional[str]) -> Optional[str]:
if string is not None:
return normalize("NFC", string)
else:
return None
if "edge_media_to_caption" in self._node and self._node["edge_media_to_caption"]["edges"]: if "edge_media_to_caption" in self._node and self._node["edge_media_to_caption"]["edges"]:
return normalize("NFC", self._node["edge_media_to_caption"]["edges"][0]["node"]["text"]) return _normalize(self._node["edge_media_to_caption"]["edges"][0]["node"]["text"])
elif "caption" in self._node: elif "caption" in self._node:
return normalize("NFC", self._node["caption"]) return _normalize(self._node["caption"])
return None return None
@property @property