Conversation
- Remove generic ' ' prefix from commentPrefixes to prevent false positives
- Add getCommentPrefixesForFile() for file-type-aware prefix detection
- Track {{! ... }} comment block state for .hbs files
- Only apply indented prefix detection inside {{! }} blocks
- Prevents JavaScript code in <script> tags from being modified
- Updates tests to pass inHbsCommentBlock parameter
57161ff to
87cd945
Compare
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.
🛠️ Description
This PR fixes a critical bug where JavaScript code was being incorrectly identified and modified as copyright headers, corrupting the code. The issue occurred because the copyright detection logic used a generic " " (two spaces) prefix that matched any indented content containing the word "copyright" across all file types.
What changed:
commentPrefixesarray to prevent false positivesgetCommentPrefixesForFile()that returns context-appropriate prefixes based on file type and location within the fileextractAllCopyrightInfo()to detect {{! ... }} boundaries in .hbs fileshbsIndentedPrefixesarray (containing " " and "\t") that only applies inside .hbs comment blocksparseCopyrightLine()to acceptinHbsCommentBlockparameter for context-aware parsingfilePathandinHbsCommentBlockfieldsWhy:
The previous implementation treated any indented line containing "copyright" as a copyright header, regardless of file type or context. This caused JavaScript code like
copyright: 'Copyright xyz Inc.'in .hbs files to be incorrectly modified. The new file-aware approach ensures that indented copyright detection only applies within actual comment blocks in .hbs files, leaving embedded code untouched.Impact:
<script>tags is no longer touched🔗 External Links
N/A
👍 Definition of Done
🤔 Can be merged upon approval?
✅
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request. - Simple revert of PR will restore previous behavior
If applicable, I've documented the impact of any changes to security controls. - No changes to security controls; this is a bug fix for copyright header detection logic