Skip to content

Adds more robust copy/paste checking - #15

Merged
jrj221 merged 2 commits into
mainfrom
approved-paste-matching
Nov 5, 2026
Merged

jrj221 merged 2 commits into
mainfrom
approved-paste-matching

Conversation

@jrj221

@jrj221 jrj221 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Surround edits are IDE actions: _is_surround_edit treats an edit as an IDE action when its new text is exactly the old text wrapped in ', ", `, ''', """, (), [] or {}.

  • Edited pastes keep their classification: _classify_cluster now checks the text as first pasted as well as the final text, for both the approved and internal checks. Before, a change inside the burst could leave a final text that never existed. For example, if you had the text ("Jack","Johnson") and copied and pasted it internally, PyCharm automatically inserts a space after the comma so that it becomes ("Jack", "Johnson") which gets flagged as unapproved instead of internal.

  • --approved-pastes FILE [FILE ...] takes one or more files: Previously the flag only accepted one file. This change was made so that recan can be run with expected test output and instructions as arguments so that students copying and pasting from them (ex. copying Enter a Number: from the expected output) are flagged as approved pastes instead of unapproved.

  • Loose approved matching: runs as a second chance after the exact text check fails. It drops # and Markdown line markers, **, backticks and typographic quotes, and collapses whitespace. This change was made to normalize content students copy from canvas or test output.

Tests

38 new tests; the total goes from 148 to 186. They cover:

  • surround pairs and look-alikes
  • an edit inside a paste burst, in both directions
  • several approved paste files
  • loose matching, the 12-character floor (minimum amount of text in a loose match compare), and genuine non-matches

…roved matching

- Wrapping selected text in a quote/bracket pair (one edit, old -> opener+old+closer)
  is an IDE action, not a paste.
- A paste of internal/approved text stays internal/approved when another edit in the
  same 250 ms burst changes it; the text as first pasted is checked as well as the
  final text.
- --approved-pastes takes one or more files, each its own source.
- Approved pastes get a second, looser match: comment/Markdown line markers, bold and
  code marks and typographic quotes are ignored and whitespace is collapsed, so text
  copied from the rendered instructions matches the Markdown source. Needs at least
  12 characters after simplifying.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comment thread CHANGELOG.md Outdated

## Unreleased

- Approved pastes are matched loosely as a second chance: line markers (`#`, Markdown headings, list numbers and bullets), bold and code marks and typographic quotes are ignored, and line wraps and runs of whitespace don't matter. A paste of instructions copied from the rendered page now matches the Markdown source. Code is not made whitespace-insensitive (`x=1` still differs from `x = 1`). The loose match needs at least 12 characters after simplifying, so a marker can't shrink a short paste (`- a`) into a match.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 12 characters? Why not fewer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original idea was that if a student pasted something really short like - the the loose checking would strip out the hyphen and leading space to result in just the which is extremely likely to match something from the instructions just in the nature of being such a short/common substring. The 12 was an arbitrary limit.

On reflection, I can't think of a scenario where this behavior could be used maliciously by a student, so I just dropped the minimum check altogether. If they want to paste - the for whatever reason, I don't see a reason to flag it.

@byubean

byubean commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Need to bump the version (VERSION and Changelog).

@jrj221
jrj221 merged commit ed75a96 into main Nov 5, 2026
1 check passed
@jrj221
jrj221 deleted the approved-paste-matching branch November 5, 2026 18:49
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