Skip to content

fix: harden readSecret newline handling and add phpinfo version - #52

Merged
prateekbhujel merged 1 commit into
mainfrom
fix/harden-read-secret-and-phpinfo
Aug 16, 2026
Merged

fix: harden readSecret newline handling and add phpinfo version#52
prateekbhujel merged 1 commit into
mainfrom
fix/harden-read-secret-and-phpinfo

Conversation

@prateekbhujel

Copy link
Copy Markdown
Owner

What

Fixes readSecret() terminal output behavior and adds quality-of-life improvements.

readSecret() newline on Enter

readSecret() now prints a newline to stdout when the user presses Enter, so subsequent output starts on a fresh line. Previously the caller's next output would continue on the same line as the *** mask. Applies to both POSIX and Windows.

readSecret() newline on abort

readSecret() now prints a newline to stdout when the user aborts with Ctrl-C, Ctrl-D, or Escape, so the terminal prompt stays clean before the thrown error. Applies to both POSIX and Windows.

Dead code removal

Removed the written != (zend_long) ZSTR_LEN(prompt) partial-write check in the readSecret() prompt path — terminal_stream_write() already loops until all bytes are written or returns false on failure, so this check was unreachable.

Windows ZTS correctness

Marked terminal_win_stdin_is_raw as volatile so the compiler doesn't reorder or cache reads of this process-global flag around SetConsoleMode calls in ZTS builds.

phpinfo() version

phpinfo() now displays the extension version alongside backend and support status.

Tests

  • tests/025_read_secret_newline.phpt — verifies newline is printed after Enter
  • tests/026_read_secret_abort.phpt — verifies newline is printed before the thrown error on Ctrl-C abort

Verification

  • XAMPP PHP 8.2 x86_64 build from /private/tmp with -Wall -Wextra: no warnings
  • PHPT: 36 total, 33 passed, 3 expected skips, 0 failed
  • php -i | grep terminal confirms version display

- readSecret() now prints a newline to stdout when the user presses
  Enter, so subsequent output starts on a fresh line (POSIX + Windows)
- readSecret() now prints a newline on Ctrl-C/Ctrl-D/Escape abort so
  the terminal stays clean (POSIX + Windows)
- Removed dead partial-write check in readSecret() prompt write path;
  terminal_stream_write() already loops until completion
- Marked terminal_win_stdin_is_raw as volatile for correct compiler
  behavior under ZTS builds
- phpinfo() now displays the extension version
- Added tests/025 and tests/026 for the newline behavior
@prateekbhujel
prateekbhujel merged commit 1b398a2 into main Aug 16, 2026
15 checks passed
@prateekbhujel
prateekbhujel deleted the fix/harden-read-secret-and-phpinfo branch August 16, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant