Enhance Template Tags and Filters for Improved Functionality and Main… #9473
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.
…tainability
This commit introduces several improvements to the template tags and filters used in Django Rest Framework (DRF). The enhancements focus on code readability, maintainability, efficiency, and security. Key changes include:
Enhancements:
Regex Precompilation:
Simplified Add Class Function:
add_class
function for better readability and efficiency, ensuring that CSS classes are added accurately and safely.Modularized and Documented Code:
Security Enhancements:
mark_safe
to prevent XSS attacks, particularly in functions dealing with user-generated content.Optimized Markdown Rendering:
apply_markdown
function and provided safe fallbacks, enhancing the robustness of markdown rendering.Improved Handling of Dynamic URLs and Headers:
Detailed Changes:
add_class
logic by reducing regex operations and ensuring accurate class insertion.escape
andmark_safe
appropriately.apply_markdown
and usingmark_safe
.These changes aim to enhance the overall functionality, readability, and security of the template tags and filters, contributing to a more robust and maintainable codebase for Django Rest Framework.
Note: Before submitting a code change, please review our contributing guidelines.
Description
Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use
refs #...
in the description of the pull request.