Skip to content

Commit 3567df0

Browse files
authored
Merge pull request #1037 from fa0311/fix/script-loading
fix: escape regex in twitter.py, md_generator.py, legacy.py, js_parse…
2 parents 1da1e1e + f5520e9 commit 3567df0

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

lib/graphql.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99

1010
def get_graphql(parsed_list: JsData) -> list:
11-
reg_graphql = "e\.graphQL\({func}\(\),$".format(func="([a-zA-Z_\$]{1,2})")
11+
reg_graphql = r"e\.graphQL\({func}\(\),$".format(func=r"([a-zA-Z_$]{1,2})")
1212
graphql_list = search_js_reg(parsed_list, reg_graphql)
1313
graphql_output = []
1414

1515
for graphql in tqdm(graphql_list):
16-
reg_func = "{func}=t.n\({arg}\)".format(
16+
reg_func = r"{func}=t.n\({arg}\)".format(
1717
func=re.escape(graphql.data[0]),
18-
arg="([a-zA-Z_\$]{1,2})",
18+
arg=r"([a-zA-Z_$]{1,2})",
1919
)
2020

2121
graphql_parent = graphql.parent
@@ -28,9 +28,9 @@ def get_graphql(parsed_list: JsData) -> list:
2828

2929
if match_func == []:
3030
continue
31-
reg_func_init = "{func}=t\({arg}\)".format(
31+
reg_func_init = r"{func}=t\({arg}\)".format(
3232
func=re.escape(match_func[0].data[0]),
33-
arg="([0-9]{1,5})",
33+
arg=r"([0-9]{1,5})",
3434
)
3535
match_func_init = search_js_reg(graphql_parent, reg_func_init)
3636
if match_func_init == []:
@@ -58,7 +58,7 @@ def marge_exports(parsed_list: list, graphql_output: list) -> list:
5858
reg_exports = "{comma}{int}:{var}=>".format(
5959
comma=",?",
6060
int="([0-9]{1,5})",
61-
var="(e|\([a-z,]*?\))",
61+
var=r"(e|\([a-z,]*?\))",
6262
)
6363
for export in exports:
6464
n = re.findall(reg_exports, export.parent.before)[0][0]
@@ -142,7 +142,7 @@ def marge_metadata(graphql_output: list, feature_switch: dict) -> list:
142142

143143

144144
def get_freeze_object(parsed_list: list, disable_tqdm=True) -> list:
145-
reg_freeze_object = "Object\.freeze\($"
145+
reg_freeze_object = r"Object\.freeze\($"
146146
freeze_object_list = search_js_reg(parsed_list, reg_freeze_object)
147147
freeze_object_output = []
148148

@@ -158,7 +158,7 @@ def get_freeze_object(parsed_list: list, disable_tqdm=True) -> list:
158158

159159

160160
def get_feature_switches(parsed_list: list) -> list:
161-
reg_exports = "e\.exports={var}$".format(var="([a-zA-Z]{1,2})")
161+
reg_exports = r"e\.exports={var}$".format(var=r"([a-zA-Z]{1,2})")
162162
exports_list = search_js_reg(parsed_list, reg_exports)
163163
for exports in exports_list:
164164
feature_switches = get_freeze_object(exports.parent, disable_tqdm=True)

lib/js_parser/js_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def search_js_reg(text: JsData, search: str) -> list[JsSearchData]:
119119

120120
def json_parser(text: JsData):
121121
output = ""
122-
reg_other = "[0-9a-zA-Z\s" + re.escape("!?$_.{}&=") + "]"
122+
reg_other = r"[0-9a-zA-Z\s" + re.escape("!?$_.{}&=") + "]"
123123
for data in text.children:
124124
if type(data) is JsData:
125125
json = json_parser(data)
@@ -133,14 +133,14 @@ def json_parser(text: JsData):
133133
placeholder = parentheses_placeholder(data)
134134
json_child = ""
135135
json = re.sub(
136-
f"(,|^)(\.\.\.{reg_other}+)(,|$)",
136+
rf"(,|^)(\.\.\.{reg_other}+)(,|$)",
137137
r'\1"\2":"_"\3',
138138
placeholder.text,
139139
)
140140
while json_child != json:
141141
json_child = json
142142
json = re.sub(
143-
f"(,|^)(\.\.\.{reg_other}+)(,|$)",
143+
rf"(,|^)(\.\.\.{reg_other}+)(,|$)",
144144
r'\1"\2":"_"\3',
145145
json_child,
146146
)

lib/legacy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def get_dispatch_list():
2020

2121

2222
def get_dispatch(parsed_list: JsData) -> dict:
23-
reg_graphql = 'e.{method}\("{queryId}",'.format(
23+
reg_graphql = r'e.{method}\("{queryId}",'.format(
2424
method="({0})".format("|".join(get_dispatch_list().keys())),
25-
queryId="([a-z_/]*?)",
25+
queryId=r"([a-z_/]*?)",
2626
)
2727
dispatch_list = search_js_reg(parsed_list, reg_graphql)
2828
dispatch_list_unique: list[JsSearchData] = []

lib/md_generator/md_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def table(self, data: dict, end: str = "\n\n"):
3535

3636
def table_escape(self, text: str):
3737
if type(text) is str:
38-
return text.replace("|", "\|")
38+
return text.replace("|", r"\|")
3939
else:
4040
return text
4141

lib/twitter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ def get_header(self):
8181
}
8282

8383
def get_script_url(self) -> list[str]:
84-
src = "(https://abs\.twimg\.com\/{0}\/client-web\/[a-zA-Z0-9\.]*?\.js)".format(
84+
src = r"(https://abs\.twimg\.com\/{0}\/client-web\/[a-zA-Z0-9\.]*?\.js)".format(
8585
re.escape(self.CLIENT)
8686
)
8787
reg_script = '<script type="text/javascript" charset="utf-8" nonce="{nonce}" crossorigin="anonymous" src="{src}"></script>'.format(
88-
nonce="([a-zA-Z0-9]{48})",
88+
nonce=r"([a-zA-Z0-9]{48})",
8989
src=src,
9090
)
9191
return [url[1] for url in re.findall(reg_script, self.response.text)]
9292

9393
def get_script(self, response: str) -> list[str]:
9494
reg_script = '<script type="text/javascript" charset="utf-8" nonce="{nonce}">{any}</script>'.format(
95-
nonce="([a-zA-Z0-9]{48})",
96-
any="([\s\S]*?)",
95+
nonce=r"([a-zA-Z0-9]{48})",
96+
any=r"([\s\S]*?)",
9797
)
9898
return [script[1] for script in re.findall(reg_script, response)]
9999

0 commit comments

Comments
 (0)