Skip to content

PathSanitizingFileCheck: improve Python3 compatibility #32653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions utils/PathSanitizingFileCheck
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,21 @@ constants.""")

if args.enable_windows_compatibility:
if args.enable_yaml_compatibility:
slashes_re = b'(/|\\\\\\\\|\\\\\\\\\\\\\\\\)'
slashes_re = r'(/|\\\\|\\\\\\\\)'
else:
slashes_re = b'(/|\\\\\\\\)'
slashes_re = r'(/|\\\\)'
else:
slashes_re = b'/'
slashes_re = r'/'

stdin = io.open(sys.stdin.fileno(), 'rb').read()
stdin = io.open(sys.stdin.fileno(), 'r', encoding='utf-8', errors='ignore').read()

for s in args.sanitize_strings:
replacement, pattern = s.encode(encoding="utf-8").split(b'=', 1)
replacement, pattern = s.split('=', 1)
# Since we want to use pattern as a regex in some platforms, we need
# to escape it first, and then replace the escaped slash
# literal (r'\\/') for our platform-dependent slash regex.
stdin = re.sub(re.sub(b'\\\\/', slashes_re, re.escape(pattern)),
stdin = re.sub(re.sub('\\\\/' if sys.version_info[0] < 3 else r'[/\\]',
slashes_re, re.escape(pattern)),
replacement,
stdin)

Expand All @@ -90,7 +91,7 @@ constants.""")
else:
p = subprocess.Popen(
[args.file_check_path] + unknown_args, stdin=subprocess.PIPE)
stdout, stderr = p.communicate(stdin)
stdout, stderr = p.communicate(stdin.encode('utf-8'))
if stdout is not None:
print(stdout)
if stderr is not None:
Expand Down