Skip to content

loopguard: read a sed or perl script given inside its option word - #179

Merged
Aaron Li (aaron-jx-li) merged 1 commit into
microsoft:mainfrom
VISHNU0906:fix/sed-perl-inline-script
Nov 10, 2026
Merged

Aaron Li (aaron-jx-li) merged 1 commit into
microsoft:mainfrom
VISHNU0906:fix/sed-perl-inline-script

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

Hi Aaron Li (@aaron-jx-li), another small one from the shell-edit parser in loopguard/shell_edits.py.

_inplace_files only recognised a sed or perl script given as the next word (-e 's/a/b/', --file x.sed). When the script sits inside the option word, the parser took the file for the script and found no edit:

  • sed -i --expression='s/a/b/' pkg/mod.py
  • sed -i -e's/a/b/' pkg/mod.py
  • sed -i --file=fix.sed pkg/mod.py
  • perl -i -pe's/a/b/' pkg/mod.py

All four returned [] from shell_edit_targets, so TurnGuard.fold did not count the edit and the judge's digest showed no edit for that turn. With sed --in-place --expression=s/a/b/ a.py b.py, only b.py was counted.

The script flag check now returns where the script is: the next word, or inside the option itself. Short option clusters are read letter by letter, so -ne still means the next word is the script, and -i.bak, -Mre=eval or -Idir are not read as scripts.

Tests: new cases in test_edits_made_through_the_shell_are_recognised plus one through TurnGuard.fold. With the fix reverted, 6 of them fail; the other new cases (-ne, -i.orig -pe, -Mre=eval) are there to make sure those keep working. python -m pytest tests passes on Python 3.10, 3.12 and 3.13 (859 passed, 16 skipped), experiments/tests passes (393 passed), and scripts/dead_code.py reports nothing new.

This touches the same file as #176 but a different function, so the two don't conflict.

sed -i --expression='s/a/b/' f.py, sed -i -e's/a/b/' f.py,
sed -i --file=x.sed f.py and perl -i -pe's/a/b/' f.py carry the script
in the option word. The in-place parser only knew the forms where the
script is the next word, so it took f.py for the script and the edit
was never counted.

Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
@aaron-jx-li
Aaron Li (aaron-jx-li) merged commit 4f66327 into microsoft:main Nov 10, 2026
9 checks passed
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