Files
RustPython/extra_tests
Luan Taraschi cdb8a8dd83 Fix str.expandtabs aborting on a tab size of zero (#8562)
`"a\tb".expandtabs(0)` panicked with a capacity overflow. CPython returns
`'ab'`: with no width to advance to, the tabs come out and nothing else
moves. `expandtabs(-1)` is the same call, since `ExpandTabsArgs::tabsize`
sends every negative value to 0.

`expandtabs` keeps the tab stop in `tab_size` and the current column in
`col_count`, and on a tab it does `tab_size - col_count`. With a tab size of
zero both start at 0, the first character makes `col_count` 1 while
`tab_size` stays 0, and the subtraction underflows. The run of spaces asked
for next is `usize::MAX`, and the allocation aborts the process. A tab has to
follow something on the line to reach it: `"\ta".expandtabs(0)` subtracts 0
from 0 and comes out right by accident.

`BytesInner::expandtabs` already returns early for this and filters the tabs
out. The string version now does the same.

Assisted-by: Claude Code:claude-opus-5
2026-08-21 20:29:22 +09:00
..
2022-07-17 03:25:34 +09:00
2025-12-12 22:46:39 +09:00

Test snippets

This directory contains two sets of test snippets which can be run in Python. The snippets/ directory contains functional tests, and the benchmarks/ directory contains snippets for use in benchmarking RustPython's performance.

Setup

Our testing depends on pytest, which you can install using pip.

Running

Simply run pytest -v in this directory, and the tests should run (and hopefully pass). If it hangs for a long time, that's because it's building RustPython in release mode, which should take less time than it would to run every test snippet with RustPython compiled in debug mode.