Skip to content

bugfix: IndexError when 'n' exceeds length#228

Merged
jquast merged 4 commits into
masterfrom
fix-wcswidth-n-exceeds-length
Jun 29, 2026
Merged

bugfix: IndexError when 'n' exceeds length#228
jquast merged 4 commits into
masterfrom
fix-wcswidth-n-exceeds-length

Conversation

@jquast

@jquast jquast commented Jun 29, 2026

Copy link
Copy Markdown
Owner
  • fix: clamp n to len(pwcs) in wcswidth/wcstwidth to avoid IndexError
  • Cover wcswidth n overflow companion paths
  • reduce test size
  • document bugfix, prepare for 0.8.2

gaoflow and others added 4 commits June 24, 2026 22:01
Passing n > len(pwcs) to wcswidth() or wcstwidth() causes an
IndexError when the loop index reaches the end of the string, because
`end` was set to n directly.

Fix: `end = min(n, len(pwcs))` so that n larger than the string length
is treated the same as measuring the whole string, which is the natural
Python semantics for sized strings.

Adds a regression test covering ASCII, wide characters, and ZWJ clusters.
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9df7261) to head (e7e715a).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #228   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         1924      1967   +43     
  Branches       456       462    +6     
=========================================
+ Hits          1924      1967   +43     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast jquast merged commit 4c91403 into master Jun 29, 2026
33 checks passed
@jquast jquast deleted the fix-wcswidth-n-exceeds-length branch June 29, 2026 17:30
@codspeed-hq

codspeed-hq Bot commented Jun 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 108 untouched benchmarks


Comparing fix-wcswidth-n-exceeds-length (e7e715a) with master (d1c99fe)

Open in CodSpeed

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.

2 participants