Skip to content

Fix: percent-encode paths when rewriting cached Portal Engine thumbnail URLs after a move#458

Open
robertSt7 wants to merge 1 commit into
2026.2from
PEES-1245-fix-portal-thumbnail-path-encoding
Open

Fix: percent-encode paths when rewriting cached Portal Engine thumbnail URLs after a move#458
robertSt7 wants to merge 1 commit into
2026.2from
PEES-1245-fix-portal-thumbnail-path-encoding

Conversation

@robertSt7

@robertSt7 robertSt7 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

PEES-1245

resolves https://github.com/pimcore/service-operations/issues/932

Moving an asset folder whose name (or a descendant's name) contains accented characters breaks image thumbnails afterwards — but only in Portal Engine, not in the Studio backend. Moving the folder back makes the thumbnails reappear without any regeneration.

Relation to #19242 (already merged into 2026.2)

That PR fixed a real but different bug: a macOS-NFD vs NFC Unicode-normalization mismatch when Pimcore itself moves the physical thumbnail files on disk (Asset::relocateThumbnails()). It's why the Studio backend now shows correct thumbnails right after a move.

This PR fixes what's left: Portal Engine doesn't re-fetch thumbnail URLs live — it reads a cached thumbnail URL stored in the OpenSearch index (custom_fields.PortalEngineBundle.system_fields.thumbnail, populated via ThumbnailService::getThumbnailPath(), which calls Thumbnail::getPath(['frontend' => true])). That frontend path is built with urlencode_ignore_slash() (rawurlencode() per path segment), so accented characters end up percent-encoded (e.g. é%C3%A9).

When a folder moves, PathService::rewriteChildrenIndexPaths() runs a Painless script against the index to rewrite that cached field's path prefix from the old to the new path. The script only special-cased spaces (" " → "%20") before attempting the prefix match — it didn't percent-encode other characters. So for any moved folder containing accented (or other percent-encoded) characters, the match silently fails, and the cached thumbnail URL is left pointing at the pre-move path — which is exactly why it "just works" again once you move the folder back to its original location (the stale cached URL matches the restored path again).

Fix

PathService::updatePath() now also passes a fully percent-encoded variant of the old/new path (mirroring urlencode_ignore_slash() segment-by-segment) into the script, and the script matches/replaces against that as a fallback alongside the plain path — replacing the space-only special case, which this generalizes and subsumes.

Testing

  • Added PathServiceTest::testEncodePathSegments*() covering the new percent-encoding helper (accented characters, spaces, and unreserved characters left untouched).
  • I don't have a way in this environment to reproduce the full macOS-upload → move → Portal-render flow end-to-end against a live OpenSearch instance to exercise the actual Painless script path. Given the history on this ticket (the previous fix also needed the reporter/assignee's own hands-on validation before it was confirmed to reproduce/resolve), please validate this against a real repro (per the ticket's "how to reproduce" steps, checking the Portal view specifically) before merging.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

…il URLs after a move

rewriteChildrenIndexPaths() rewrites the cached thumbnail URL for moved
assets/data-objects in the search index, but only special-cased spaces
(" " -> "%20") when matching the path prefix. Portal Engine's frontend
thumbnail URLs are built via urlencode_ignore_slash() (rawurlencode()
per path segment), which percent-encodes any non-unreserved character,
including accented letters (e.g. "é" -> "%C3%A9"). So for any moved
folder containing such characters, the prefix match silently failed
and the cached thumbnail URL was left pointing at the pre-move path -
breaking images in Portal Engine while the Studio backend (which
re-fetches thumbnails live rather than reading the cached field)
appeared unaffected.

Pass a fully percent-encoded path variant into the Painless script and
match/replace against it as a fallback, instead of only handling
spaces.

PEES-1245

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@robertSt7 robertSt7 force-pushed the PEES-1245-fix-portal-thumbnail-path-encoding branch from ec16b11 to 8e684de Compare July 9, 2026 09:52
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Major Issues (required ≤ 0)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

@robertSt7 robertSt7 added this to the 2026.2.2 milestone Jul 9, 2026
@robertSt7 robertSt7 added the Bug label Jul 9, 2026
@robertSt7 robertSt7 self-assigned this Jul 9, 2026
@robertSt7 robertSt7 requested a review from Copilot July 9, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 a Portal Engine–specific regression where cached frontend thumbnail URLs stored in the OpenSearch index are not rewritten correctly after moving asset folders whose names contain percent-encoded characters (e.g., accented characters). It extends the existing OpenSearch “rewrite children paths” Painless script to also match/replace percent-encoded path prefixes, aligning the rewrite logic with how Portal Engine constructs thumbnail URLs.

Changes:

  • Pass both plain and per-segment percent-encoded variants of the old/new paths into the OpenSearch update-by-query script.
  • Update the Painless script to match/replace using the encoded prefix as a fallback (generalizing the previous space-only handling).
  • Add unit tests covering the new path-segment percent-encoding helper (accented characters, spaces, unreserved characters).

Reviewed changes

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

File Description
src/SearchIndexAdapter/DefaultSearch/PathService.php Adds per-segment percent-encoded path parameters and updates the Painless script to rewrite cached Portal Engine thumbnail URLs reliably after moves.
tests/Unit/SearchIndexAdapter/DefaultSearch/PathServiceTest.php Adds regression-focused unit tests validating the per-segment percent-encoding behavior used by the rewrite logic.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants