WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
264237
[meta] Python CGI should use binary mode for stdout for Windows Python
https://bugs.webkit.org/show_bug.cgi?id=264237
Summary
[meta] Python CGI should use binary mode for stdout for Windows Python
Fujii Hironori
Reported
2023-11-05 22:42:33 PST
[meta] Python CGI should use binary mode for stdout for Windows Python Windows Python automatically converts '\n' to '\r\n' for text mode.
Attachments
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2023-11-12 22:43:14 PST
<
rdar://problem/118316460
>
Kohei Asano
Comment 2
2025-02-03 21:52:04 PST
Although this is just cleaning for pre-existing file only, but we can fix this by inserting sys.stdout.reconfigure(newline=''); ```bash C:\Users\0300093582\tmp>python -c "import sys;sys.stdout.reconfigure(newline='');sys.stdout.write('Hello\nWorld\n')" | xxd 00000000: 4865 6c6c 6f0a 576f 726c 640a Hello.World. ``` also on Linux(Ubuntu) I confirmed no effect appears ```bash [12:22] JPC00234727:tmp | python3 -c "import sys;sys.stdout.reconfigure(newline='');sys.stdout.write('Hello\nWorld\n')" | xxd 00000000: 4865 6c6c 6f0a 576f 726c 640a Hello.World. [12:24] JPC00234727:tmp | cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.4 LTS" ```
Kohei Asano
Comment 3
2025-02-03 22:19:06 PST
Pull request:
https://github.com/WebKit/WebKit/pull/39971
Kohei Asano
Comment 4
2025-02-03 22:23:16 PST
I tried to fix by the following shell script, but its lines are much more than I expected, I'm not so sure it's worth to apply all, but I leave this for notes ``` I inserted by the following shell scripts, and it was #!/bin/bash TARGET_DIR="LayoutTests" grep -rl 'sys.stdout.write' "$TARGET_DIR" --include="*.py" | while read -r file; do tmpfile=$(mktemp) inserted=0 while IFS= read -r line || [[ -n "$line" ]]; do echo "$line" >> "$tmpfile" if [[ $line =~ ^[[:space:]]*import\ sys$ ]]; then indent=$(echo "$line" | grep -o '^[[:space:]]*') echo "${indent}sys.stdout.reconfigure(newline=\"\") # prevent windows \n -> \n\r conversion" >> "$tmpfile" fi done < "$file" mv "$tmpfile" "$file" done ```
Kohei Asano
Comment 5
2025-02-19 04:35:07 PST
> Pull request:
https://github.com/WebKit/WebKit/pull/39971
I'm sorry, I think PR itself is a little bothering because of too much noises. Also I learned meta issue meaning. Thanks!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug