-
Notifications
You must be signed in to change notification settings - Fork 8
[CMG-769] #858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CMG-769] #858
Conversation
There was a problem hiding this 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 addresses CMG-769 to fix XML file validation logic for different CMS types, specifically to prevent AEM files with XML extensions from being validated.
- Modified XML validation conditional to only validate XML files for WordPress and Drupal CMS types
- Cleaned up UI component code including console statements and improved accessibility attributes
- Simplified file format display logic
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| upload-api/src/services/fileProcessing.ts | Added CMS type check to XML validation condition to exclude AEM files from WordPress/Drupal XML processing |
| ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx | Removed debug console statements, added label prop, improved value display logic, and updated icon condition check |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if (fileExt === 'xml' && (cmsType === 'wordpress' || cmsType === 'drupal')) { | ||
| if (await validator({ data: zipBuffer, type: cmsType, extension: fileExt })) { |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change has two issues:
-
Drupal XML validation will fail: The condition now allows
cmsType === 'drupal', but the validator function doesn't have a case for 'drupal-xml'. When called with type='drupal' and extension='xml', the validator will return false (default case), causing all Drupal XML files to be rejected. -
AEM files still validated: According to the PR description, AEM files with XML extensions should not be validated. However, with this change, AEM XML files will skip this block (which is correct) but then fall through to the else block (lines 95-119) where they'll still be validated. Since there's no 'aem-xml' validator case, they'll fail validation and be rejected.
Consider adding appropriate validator cases in validators/index.ts for 'drupal-xml' and any AEM file extensions that should be supported without validation.
| } else if (fileExt === 'xml' && (cmsType === 'wordpress' || cmsType === 'drupal')) { | |
| if (await validator({ data: zipBuffer, type: cmsType, extension: fileExt })) { | |
| } else if (fileExt === 'xml' && cmsType === 'aem') { | |
| // For AEM XML files, skip validation and accept the file | |
| const $ = Cheerio.load(zipBuffer, { xmlMode: true }); | |
| const fixedXml = $.xml(); | |
| const parsedJson = await parseXmlToJson(fixedXml); | |
| const isSaved = await saveJson(parsedJson, `${name}.json`); | |
| if (isSaved) { | |
| logger.info('AEM XML file accepted without validation:', { | |
| status: HTTP_CODES?.OK, | |
| message: HTTP_TEXTS?.VALIDATION_SUCCESSFULL | |
| }); | |
| return { | |
| status: HTTP_CODES?.OK, | |
| message: HTTP_TEXTS?.VALIDATION_SUCCESSFULL, | |
| file_details: config | |
| }; | |
| } else { | |
| logger.warn('AEM XML file save error:', { | |
| status: HTTP_CODES?.UNAUTHORIZED, | |
| message: HTTP_TEXTS?.VALIDATION_ERROR | |
| }); | |
| return { | |
| status: HTTP_CODES?.UNAUTHORIZED, | |
| message: HTTP_TEXTS?.VALIDATION_ERROR, | |
| file_details: config | |
| }; | |
| } | |
| } else if (fileExt === 'xml' && (cmsType === 'wordpress' || cmsType === 'drupal')) { | |
| // For Drupal and WordPress XML files, validate appropriately | |
| let validatorType = cmsType; | |
| if (cmsType === 'drupal' && fileExt === 'xml') { | |
| validatorType = 'drupal-xml'; // Use a specific validator type for Drupal XML | |
| } | |
| if (await validator({ data: zipBuffer, type: validatorType, extension: fileExt })) { |
| prefix={ | ||
| <Icon | ||
| icon={fileIcon ? fileIcon : 'CrashedPage'} | ||
| icon={fileIcon === 'DIRECTORY' ? 'Folder' : fileIcon ? fileIcon : 'CrashedPage'} |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent folder/directory handling. The old code checked fileIcon === 'Folder' for both the value display and icon selection. The new code checks fileIcon === 'DIRECTORY' on line 89, but there's no code that sets fileIcon to 'DIRECTORY'. The fileIcon is set from selectedFileFormat?.title (lines 70, 73) or extracted from the file extension (line 59), neither of which would produce 'DIRECTORY'. This means the Folder icon will never be shown. Consider changing line 89 to check for fileIcon === 'Folder' instead.
| icon={fileIcon === 'DIRECTORY' ? 'Folder' : fileIcon ? fileIcon : 'CrashedPage'} | |
| icon={fileIcon === 'Folder' ? 'Folder' : fileIcon ? fileIcon : 'CrashedPage'} |
This PR contains fix
[CMG-769] - If the CMS type is AEM, and the uploaded file path has an extension like .xml or something else, the system still validates it — but it should not.