Skip to content

Commit 1103c45

Browse files
committed
fix(app): 修复控制字符导致程序报错的问题
Closes #359
1 parent b1d99ab commit 1103c45

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

source/expansion/converter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from typing import Union
2-
2+
from re import compile
33
from lxml.etree import HTML
44
from yaml import safe_load
55

66
__all__ = ["Converter"]
77

88

99
class Converter:
10+
YAML_ILLEGAL = compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]")
1011
INITIAL_STATE = "//script/text()"
1112
PC_KEYS_LINK = (
1213
"note",
@@ -30,9 +31,10 @@ def _extract_object(self, html: str) -> str:
3031
scripts = html_tree.xpath(self.INITIAL_STATE)
3132
return self.get_script(scripts)
3233

33-
@staticmethod
34-
def _convert_object(text: str) -> dict:
35-
return safe_load(text.lstrip("window.__INITIAL_STATE__="))
34+
@classmethod
35+
def _convert_object(cls, text: str) -> dict:
36+
cleaned = cls.YAML_ILLEGAL.sub("", text.lstrip("window.__INITIAL_STATE__="))
37+
return safe_load(cleaned)
3638

3739
@classmethod
3840
def _filter_object(cls, data: dict) -> dict:

static/Release_Notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**项目更新内容:**
22

33
1. 修复 CLI 模式 KeyError 异常
4+
2. 修复控制字符导致程序报错的问题
45

56
*****
67

0 commit comments

Comments
 (0)