Skip to content

Commit 1442900

Browse files
committed
ディレクトリ構造の検査でリダイレクトファイルを無視するよう変更
1 parent b0876d5 commit 1442900

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test-directory-structure.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
from html.parser import HTMLParser
23
from pathlib import Path
34

45
"""
@@ -12,6 +13,39 @@
1213
"""
1314

1415

16+
class Parser(HTMLParser):
17+
"""
18+
<meta http-equiv="refresh"> を含むファイルを検査の対象から除外する
19+
"""
20+
21+
def __init__(self, *, convert_charrefs: bool = True) -> None:
22+
super().__init__(convert_charrefs=convert_charrefs)
23+
self.is_redirect = False
24+
25+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
26+
if self.is_redirect:
27+
return
28+
29+
if tag != "meta":
30+
return
31+
32+
for attr_name, attr_value in attrs:
33+
if attr_name == "http-equiv" and attr_value == "refresh":
34+
self.is_redirect = True
35+
break
36+
37+
38+
def is_redirect(path: str) -> bool:
39+
with open(path) as fp:
40+
content = fp.read()
41+
42+
parser = Parser()
43+
parser.feed(content)
44+
parser.close()
45+
46+
return parser.is_redirect
47+
48+
1549
def main() -> int:
1650
allowed_names = ["index.html", "404.html"]
1751
errors = list[str]()
@@ -25,6 +59,9 @@ def main() -> int:
2559
continue
2660

2761
path = cwd.joinpath(file).as_posix()
62+
if is_redirect(path):
63+
continue
64+
2865
errors.append(path)
2966

3067
if 0 < len(errors):

0 commit comments

Comments
 (0)