Skip to content

Conversation

@BD-Hypercall88
Copy link

@BD-Hypercall88 BD-Hypercall88 commented Dec 3, 2025

Fixed file type detection logic to check filenames before directory paths,
preventing formatter from corrupting JSON files in directories whose names
contain content type keywords.

Problem:
The find_type_by_path() function used directory substring matching before
checking specific filenames. When a directory path contained content type
names (e.g., "Lists", "Jobs"), ANY JSON file in that directory would be
misdetected as that content type, even if it had a specific purpose like
pack_metadata.json.

This caused the formatter to apply wrong transformations to misdetected files,
stripping required fields and corrupting file structure.

Example Impact:

  • pack_metadata.json in "Packs/My_Lists/" detected as List file
  • Formatter stripped metadata fields: support, currentVersion, author, categories
  • Pack became unusable after format operation

Root Cause:
Line ordering in find_type_by_path():

  • Line 1678: Checked LISTS_DIR in os.path.dirname(path) (directory substring)
  • Line 1692: Checked path.name == PACKS_PACK_META_FILE_NAME (filename)
  • Directory check matched first, returned wrong FileType

Solution:
Reordered checks to prioritize filename-based detection:

  1. Check specific filenames first (pack_metadata.json, etc.)
  2. Then check directory-based patterns
  3. Added comment explaining the requirement

Testing:

  • Unit test: pack_metadata.json in Lists-named directory detected correctly
  • Integration test: Formatter preserves all fields in pack_metadata.json
  • Integration test: Split list files handled without corruption
  • All existing tests pass

Prevents formatter corruption for any file with specific naming in directories
containing content type keywords.

relates: https://jira-dc.paloaltonetworks.com/browse/CIAC-15453

@BD-Hypercall88 BD-Hypercall88 requested a review from a team as a code owner December 3, 2025 18:03
@CLAassistant
Copy link

CLAassistant commented Dec 3, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the Contribution Thank you! Contributions are always welcome! label Dec 3, 2025
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

Thank you for your contribution. Your willingness to improve our product and contribute to our community is highly appreciated. For your convenience, here is a link to the contributions SLAs document.

…tection

Fixed file type detection logic to check filenames before directory paths,
preventing formatter from corrupting JSON files in directories whose names
contain content type keywords.

**Problem:**
The find_type_by_path() function used directory substring matching before
checking specific filenames. When a directory path contained content type
names (e.g., Lists, Jobs), ANY JSON file in that directory would be
misdetected as that content type, even if it had a specific purpose like
pack_metadata.json.

This caused the formatter to apply wrong transformations to misdetected files,
stripping required fields and corrupting file structure.

**Example Impact:**
- pack_metadata.json in Packs/My_Lists/ detected as List file
- Formatter stripped metadata fields: support, currentVersion, author, categories
- Pack became unusable after format operation

**Root Cause:**
Line ordering in find_type_by_path():
- Line 1678: Checked  (directory substring)
- Line 1692: Checked  (filename)
- Directory check matched first, returned wrong FileType

**Solution:**
Reordered checks to prioritize filename-based detection:
1. Check specific filenames first (pack_metadata.json, etc.)
2. Then check directory-based patterns
3. Added comment explaining the requirement

**Testing:**
- Unit test: pack_metadata.json in Lists-named directory detected correctly
- Integration test: Formatter preserves all fields in pack_metadata.json
- Integration test: Split list files handled without corruption
- All existing tests pass

Prevents formatter corruption for any file with specific naming in directories
containing content type keywords.
@BD-Hypercall88 BD-Hypercall88 force-pushed the fix-lists-pack-metadata-detection branch from 3d067e4 to ef9c0d6 Compare December 3, 2025 18:15
@BD-Hypercall88 BD-Hypercall88 changed the title fix: prioritize filename checks over directory checks in file type de… fix: prioritize filename checks over dir checks in file type detection Dec 3, 2025
@JasBeilin JasBeilin assigned BEAdi and unassigned JasBeilin Dec 17, 2025
@merit-maita merit-maita reopened this Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contribution Thank you! Contributions are always welcome!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants