fix: apply consistent surrogate-sanitizing read. - #756
Open
StarsExpress wants to merge 10 commits into
Open
Conversation
StarsExpress
marked this pull request as draft
August 11, 2026 19:50
1. tools/file_modifications.py — _delete_snippet_from_file, _replace_in_file, _write_to_file. 2. plugins/file_permission_handler/register_callbacks.py.
StarsExpress
force-pushed
the
fix-read-text-sanitized
branch
from
August 12, 2026 03:30
c185cc1 to
5d97b0d
Compare
StarsExpress
marked this pull request as ready for review
August 12, 2026 04:05
Contributor
Author
|
@mpfaffenberger Hello Michael. Regarding issue #463's repeated surrogate-sanitizing file read code, I have prepared this PR as a surrogate sanitization consistency & robustness fix. |
Found & aligned another repeated code block in _delete_file_async of code_puppy/tools/file_modifications.py.
Contributor
Author
|
Updated: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs issue #463 to align repeated "read file + sanitize surrogates" block.
Repeated code block
Issue #463 cites 4 duplicated call sites (excluding the recently deleted
code_puppy/plugins/file_permission_handler.pyin 27efe8f):tools/file_modifications.py—_delete_snippet_from_file,_replace_in_file,_write_to_file.tools/file_operations.py—_read_file.Actual count — 4 + 2 = 6:
file_modifications.pyhas 4th site at_delete_file, and 5th site at_delete_file_async.All 6 repeated calls are covered by this PR.
Correction
On issue #463's framing:
_read_filedoesn't actually have "better fallback" as described — it only useserrors="surrogateescape"on open with zero post-read cleanup, making it currently the least robust of 6 call sites.3-layer fallback
_sanitize_stringalready existed and was used by 13 other call sites; unifying viaread_text_sanitizedbrings_read_fileup to that same standard for the first time.What has changed
Moves
_sanitize_stringfromcode_puppy/tools/file_operations.pytocode_puppy/tools/common.py, sincefile_operations.pyalready depends oncommon.pyregardingresolve_pathimport.Thus, its
TestSanitizeStringmoves fromtests/tools/test_file_operations_coverage.pytotests/tools/test_common_full_coverage.py.Defines
read_text_sanitizednext toatomic_write_textinsidecode_puppy/tools/common.py.Aligns the aforementioned 8 repeated occurrences with
read_text_sanitized.Adds some blank lines in these 8 repeated sites to enhance code readability.