Files
SingBox-Gopanel/scratch/scan_encoding.py
CN-JS-HuiBai f4af50299c
Some checks failed
build / build (api, amd64, linux) (push) Failing after -50s
build / build (api, arm64, linux) (push) Failing after -51s
build / build (api.exe, amd64, windows) (push) Failing after -51s
修复添加引号的错误
2026-04-18 12:36:41 +08:00

36 lines
1.1 KiB
Python

import os
def check_encoding(file_path):
try:
with open(file_path, 'rb') as f:
content = f.read()
content.decode('utf-8')
# Also check for commonMojibake patterns or literal strings
# U+FFFD is b'\xef\xbf\xbd' in UTF-8
if b'\xef\xbf\xbd' in content:
return "Contains U+FFFD (Replacement Character)"
return None
except UnicodeDecodeError as e:
return f"Invalid UTF-8 at byte {e.start}"
except Exception as e:
return str(e)
search_dir = r"d:\Development\SingBox-Gopanel"
extensions = ('.go', '.js', '.jsx', '.ts', '.tsx', '.html', '.css', '.json', '.sql', '.md')
exclude_dirs = {'.git', 'node_modules', 'dist'}
results = []
for root, dirs, files in os.walk(search_dir):
dirs[:] = [d for d in dirs if d not in exclude_dirs]
for file in files:
if file.endswith(extensions):
full_path = os.path.join(root, file)
issue = check_encoding(full_path)
if issue:
results.append(f"{full_path}: {issue}")
if results:
print("\n".join(results))
else:
print("No issues found in source files.")