Skip to content

fix: avoid DOMDocument in favicon parsing#11801

Closed
ChiragAgg5k wants to merge 4 commits into1.9.xfrom
codex/favicon-no-domdocument
Closed

fix: avoid DOMDocument in favicon parsing#11801
ChiragAgg5k wants to merge 4 commits into1.9.xfrom
codex/favicon-no-domdocument

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

What

Replace DOMDocument::loadHTML() in the favicon avatar route with inline <link> tag parsing.

Why

The favicon route only needs to read href, rel, and sizes from icon <link> tags. Using DOMDocument pulls in libxml HTML parsing for that small task, and this path was failing under the coroutine server.

This change keeps the existing behavior intact:

  • fetch the page HTML
  • inspect icon <link> tags
  • prefer svg
  • otherwise choose the largest ico / png / jpg / jpeg
  • fall back to /favicon.ico

Scope

This PR only changes:

  • src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php

Verification

  • composer format src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php
  • composer lint src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php
  • docker compose exec -T appwrite test tests/e2e/Services/Avatars --filter='/::testGetFavicon$/'
  • docker compose exec -T appwrite test tests/e2e/Services/GraphQL/AvatarsTest.php --filter='/::testGetFavicon$/'

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 6, 2026

Greptile Summary

This PR replaces DOMDocument::loadHTML() in the favicon avatar route with a regex-based approach to extract <link> icon tags from the fetched HTML. The fix is motivated by DOMDocument failures under the coroutine (Swoole) server.

The implementation:

  • Pre-strips HTML comments (<!-- ... -->), <script>, and <style> blocks before running preg_match_all for <link> tags
  • Parses tag attributes with a regex supporting double-quoted, single-quoted, and bare attribute values
  • Uses !== '' strict comparisons (instead of the prior falsy ?: operator) to correctly resolve the active attribute value capture group
  • Preserves all existing logic: SVG prioritization, largest-icon selection by sizes, and /favicon.ico fallback

Both issues flagged in previous review threads have been correctly addressed: the attribute-value falsy-coalesce is now strict (!== ''), and HTML comment pre-stripping is in place before link-tag scanning. No new P0 or P1 issues are introduced.

Confidence Score: 5/5

This PR is safe to merge; it is a targeted, well-scoped fix with no new correctness issues.

Both previously identified issues (falsy attribute coalesce and HTML comment handling) have been properly resolved. The regex-based approach correctly preserves all prior behavior: SVG prioritization, largest-icon selection, and /favicon.ico fallback. No P0 or P1 issues remain. Remaining theoretical edge cases (script tag with embedded > in attribute, reversed rel token order) are pre-existing or extremely low-impact and do not affect real-world favicon detection.

No files require special attention.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Replaces DOMDocument HTML parsing with regex-based link tag extraction; comment stripping and strict attribute value checks correctly address both prior review findings

Reviews (3): Last reviewed commit: "Ignore script and style blocks in favico..." | Re-trigger Greptile

Comment thread src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Outdated
Comment thread src/Appwrite/Platform/Modules/Avatars/Http/Favicon/Get.php Outdated
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit 9e23ba1 - 1 flaky test
Test Retries Total Time Details
UsageTest::testVectorsDBStats 1 10.13s Logs
Commit 9dbc32d - 5 flaky tests
Test Retries Total Time Details
LegacyConsoleClientTest::testListDocumentsWithCache 1 282ms Logs
LegacyCustomClientTest::testCreateIndexes 1 243.22s Logs
LegacyCustomServerTest::testAttributeResponseModels 1 241.74s Logs
LegacyCustomServerTest::testUniqueIndexDuplicate 1 240.44s Logs
UsageTest::testVectorsDBStats 1 10.13s Logs
Commit 9216638 - 2 flaky tests
Test Retries Total Time Details
FunctionsClientTest::testCreateExecution 1 63.49s Logs
UsageTest::testVectorsDBStats 1 10.48s Logs

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

✨ Benchmark results

  • Requests per second: 1,620
  • Requests with 200 status code: 291,583
  • P99 latency: 0.109962878

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,620 1,311
200 291,583 235,998
P99 0.109962878 0.154691975

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.

1 participant