Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

  • Understand the current implementation and test suite
  • Replace fragile string replacement with HTML parsing approach
  • Validate that all existing tests still pass
  • Address code review feedback to reduce duplication and improve docs
  • Run security checks (no vulnerabilities found)
  • Compress parser code (removed private methods, reduced from ~60 to ~35 lines)
  • Add comprehensive unit tests for InputToS3FileRewriter class (13 tests)
  • Add additional render method tests (3 tests)
  • Add entity and character reference handlers to preserve HTML entities
  • Add tests for proper entity preservation (no double-escaping)
  • Add tests for all handlers (comment, declaration, processing instruction)
  • All tests pass with 98% coverage on forms.py parser code
  • Reply to feedback comments

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 18, 2025 19:41
Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
…tion

Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Safari support for custom element implementation Replace string replacement with HTML parser in render method Dec 18, 2025
Copilot AI requested a review from codingjoe December 18, 2025 19:45
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.72%. Comparing base (2218cd3) to head (e736b37).
⚠️ Report is 4 commits behind head on safari.

Files with missing lines Patch % Lines
s3file/forms.py 95.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           safari     #361      +/-   ##
==========================================
- Coverage   98.20%   97.72%   -0.48%     
==========================================
  Files           8        8              
  Lines         223      264      +41     
==========================================
+ Hits          219      258      +39     
- Misses          4        6       +2     
Flag Coverage Δ
python 97.72% <95.23%> (-0.48%) ⬇️
selenium-ubuntu-latest 80.68% <71.42%> (-1.83%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

@copilot please compress the parser code; it's much too verbose has has too many private functions. Please also add unit tests to cover the new class and the changes to the render-method.

Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot please compress the parser code; it's much too verbose has has too many private functions. Please also add unit tests to cover the new class and the changes to the render-method.

I've compressed the parser code from ~60 lines to ~35 lines by:

  • Removing the 2 private helper methods (_is_file_input, _write_s3_file_tag)
  • Inlining the logic directly into handler methods
  • Simplifying the docstring

Added comprehensive unit tests:

  • 7 tests for the InputToS3FileRewriter class covering transformations, attribute handling, HTML escaping, and edge cases
  • 3 additional tests for the render method to verify attribute preservation and type exclusion

All 46 tests pass with 99% coverage on forms.py. Changes committed in f1fea21.

@codingjoe codingjoe marked this pull request as ready for review December 18, 2025 20:02
Copilot AI review requested due to automatic review settings December 18, 2025 20:02
Copilot AI requested a review from codingjoe December 18, 2025 20:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the render method in S3FileInputMixin to use an HTML parser instead of fragile string replacement for transforming <input type="file"> elements to <s3-file> custom elements. This makes the transformation more robust to Django rendering changes and variations in attribute ordering.

Key changes:

  • Introduced InputToS3FileRewriter class that extends Python's HTMLParser to parse and transform HTML
  • Updated the render method to use the new parser instead of string replacement
  • Added 10 comprehensive unit tests covering parser functionality and render method behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
s3file/forms.py Added InputToS3FileRewriter HTML parser class and updated render method to use it for transforming file inputs to custom elements
tests/test_forms.py Added 7 tests for the parser class and 3 tests for the render method to verify correct transformation, attribute handling, and HTML escaping

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
codingjoe and others added 2 commits December 18, 2025 21:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codingjoe
Copy link
Owner

@copilot make sure to add tests for all handlers

Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot make sure to add tests for all handlers

Added tests for all remaining handlers:

  • test_preserves_html_comments: Tests handle_comment
  • test_preserves_declarations: Tests handle_decl
  • test_preserves_processing_instructions: Tests handle_pi

All 13 parser tests now pass with 98% coverage on forms.py. Committed in e736b37.

@codingjoe codingjoe merged commit 5e843c6 into safari Dec 18, 2025
12 of 14 checks passed
@codingjoe codingjoe deleted the copilot/sub-pr-357-yet-again branch December 18, 2025 20:32
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