Skip to content

Fixes attachment handling in client side aasx handling#1118

Merged
aaronzi merged 5 commits intoeclipse-basyx:mainfrom
aaronzi:main
Mar 19, 2026
Merged

Fixes attachment handling in client side aasx handling#1118
aaronzi merged 5 commits intoeclipse-basyx:mainfrom
aaronzi:main

Conversation

@aaronzi
Copy link
Member

@aaronzi aaronzi commented Mar 19, 2026

Related Issue

Closes #1117

This pull request improves the handling and matching of attachment file paths and names in AASX import/export logic, with a focus on robust filename sanitization and path normalization. It introduces a reusable string sanitization utility, refactors related code to use this utility, and adds comprehensive unit tests for these helpers. Additionally, ambiguity in filename-only matching is now handled explicitly to prevent incorrect file associations.

Attachment path and filename sanitization:

  • Introduced a new safeSegment utility in StringUtils.ts for sanitizing strings to be safe for path/file segments, and refactored both import and export logic to use this shared function instead of duplicating the sanitization code. (aas-web-ui/src/utils/StringUtils.ts, aas-web-ui/src/composables/AAS/AASXImport.ts, aas-web-ui/src/composables/AAS/AASXPackaging.ts) [1] [2] [3] [4]

  • Enhanced the logic in pickSupplementaryPart to match attachments using sanitized, decoded, and original filenames, and to avoid ambiguous filename-only matches by returning null if multiple candidates are found. (aas-web-ui/src/composables/AAS/AASXImport.ts)

Path normalization and candidate generation:

  • Made normalizePackagePath, packagePathCandidates, and pickSupplementaryPart public exports for better testability and modularity. (aas-web-ui/src/composables/AAS/AASXImport.ts) [1] [2] [3]

Attachment filename and path resolution:

  • Refactored resolveAttachmentFilename to be a public export, ensuring that file naming during packaging uses the new sanitization logic and falls back to safe defaults. (aas-web-ui/src/composables/AAS/AASXPackaging.ts)

Submodel element path handling:

  • Improved the traversal logic in collectAttachmentUploads to accurately handle array indices in submodel element lists and propagate parent type information, ensuring correct path construction for attachments. (aas-web-ui/src/composables/AAS/AASXImport.ts) [1] [2]

Testing improvements:

  • Added new unit tests for all key helpers in AASXImport, AASXPackaging, and StringUtils, and removed redundant regression tests now covered by these targeted tests. (aas-web-ui/tests/composables/AAS/AASXImport.test.ts, aas-web-ui/tests/composables/AAS/AASXPackaging.test.ts, aas-web-ui/tests/utils/StringUtils.test.ts, aas-web-ui/tests/composables/AAS/AASXPathHandling.test.ts) [1] [2] [3] [4] [5]

These changes collectively make attachment handling more robust, maintainable, and easier to test.

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 improves client-side AASX import/packaging behavior by making supplementary file resolution more robust, fixing attachment upload path generation for SubmodelElementList children (indexed paths), and refining thumbnail handling so internal thumbnail endpoints aren’t mistakenly treated as external.

Changes:

  • Enhance supplementary part selection by considering decoded + sanitized filename candidates.
  • Fix attachment upload idShortPath construction to include bracket indexes for SubmodelElementList items (e.g., Markings[0]).
  • Update thumbnail fetching logic to respect defaultThumbnail.isExternal while still guarding against truly external URLs.

Reviewed changes

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

File Description
aas-web-ui/src/composables/AAS/AASXPackaging.ts Adjusts external-thumbnail detection so repository-internal thumbnail endpoints aren’t skipped.
aas-web-ui/src/composables/AAS/AASXImport.ts Improves supplementary-file matching and fixes attachment upload path traversal to include list indices.

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

You can also share your feedback on Copilot code review. Take the survey.

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 improves client-side AASX attachment import/export by normalizing package paths, centralizing filename/path-segment sanitization, and fixing attachment upload path construction for SubmodelElementList indices (addressing the missing [0] issue from #1117). It also refactors key helpers to be exported for direct unit testing and updates/expands the test suite accordingly.

Changes:

  • Introduces a shared safeSegment() sanitization helper and refactors AASX import/packaging to use it.
  • Enhances supplementary-part selection logic (candidate generation + ambiguity handling) and fixes attachment upload traversal to include list indices.
  • Adds focused unit tests for StringUtils, AASXImport, and AASXPackaging helpers; removes older regression tests now covered elsewhere.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
aas-web-ui/src/utils/StringUtils.ts Adds reusable safeSegment() helper for sanitizing file/path segments.
aas-web-ui/src/composables/AAS/AASXImport.ts Exports path helpers; improves supplementary-part matching; fixes attachment traversal to include list indices.
aas-web-ui/src/composables/AAS/AASXPackaging.ts Uses shared sanitization; exports resolveAttachmentFilename; refines external thumbnail handling.
aas-web-ui/tests/utils/StringUtils.test.ts Adds unit tests for safeSegment().
aas-web-ui/tests/composables/AAS/AASXImport.test.ts Adds unit tests for new/now-exported AASX import helpers.
aas-web-ui/tests/composables/AAS/AASXPackaging.test.ts Adds unit tests for packaging helpers (fetch path + filename resolution).
aas-web-ui/tests/composables/AAS/AASXPathHandling.test.ts Removes redundant regression tests superseded by the new focused tests.

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

You can also share your feedback on Copilot code review. Take the survey.

@aaronzi aaronzi merged commit 935208b into eclipse-basyx:main Mar 19, 2026
2 checks passed
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.

[BUG] Upload of Nameplate/MarkingFiles not possible

2 participants