Skip to content

gh-146044: Fix ctrl-w (unix-word-rubout) to use whitespace word boundaries#146174

Open
kimimgo wants to merge 3 commits intopython:mainfrom
kimimgo:fix/pyrepl-ctrl-w-146044
Open

gh-146044: Fix ctrl-w (unix-word-rubout) to use whitespace word boundaries#146174
kimimgo wants to merge 3 commits intopython:mainfrom
kimimgo:fix/pyrepl-ctrl-w-146044

Conversation

@kimimgo
Copy link

@kimimgo kimimgo commented Mar 19, 2026

Fixes #146044

Summary

The unix-word-rubout command (ctrl-w) was using bow() which treats
punctuation as word separators via the syntax table. This differs from
bash/readline's unix-word-rubout which uses only whitespace as boundaries.

Changes

  • reader.py: Add bow_whitespace() method — same as bow() but only
    considers spaces and newlines as word boundaries
  • commands.py: unix_word_rubout now calls bow_whitespace() instead of bow()
  • test_reader.py: Add TestBowWhitespace class with 4 tests verifying
    the whitespace-only behavior and the difference from bow()

Example

With buffer foo.bar baz and cursor at end:

  • Before: ctrl-w deletes baz, then bar, then foo (3 operations)
  • After: ctrl-w deletes baz, then foo.bar (2 operations, matching bash)

The existing bow() method used by backward-kill-word (M-Backspace) is unchanged.

…on#146044)

The unix-word-rubout command (ctrl-w) was using syntax_table-based
word boundaries (bow()), which treats punctuation as word separators.
This differs from bash/readline's unix-word-rubout which uses only
whitespace as word boundaries.

Add bow_whitespace() method that uses whitespace-only boundaries,
and use it in unix_word_rubout instead of bow(). The existing bow()
method (used by backward-kill-word/M-Backspace) is unchanged.

Example: with 'foo.bar baz' and cursor at end:
- Before (bow): ctrl-w deletes 'baz', then 'bar', then 'foo'
- After (bow_whitespace): ctrl-w deletes 'baz', then 'foo.bar'
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 19, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 19, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Mar 19, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
okiemute04 added a commit to okiemute04/cpython that referenced this pull request Mar 19, 2026
Add a check in Parse() to prevent calls when in_callback is true,
as this violates expat's requirements and can cause crashes. Now raises
RuntimeError with a clear message.

Add tests to verify the fix and ensure normal parsing still works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctrl-w deletes words with punctuation instead of whitespace boundary

1 participant