emailobfuscator icon indicating copy to clipboard operation
emailobfuscator copied to clipboard

Fix email obfuscator by skipping emails in HTML attributes

Open Copilot opened this issue 4 months ago • 5 comments

Fix email obfuscator by skipping emails in HTML attributes

Problem

The email obfuscator was incorrectly recognizing retina image filenames (like [email protected], [email protected]) as email addresses and obfuscating them, which broke image references in HTML.

Solution

Per @skerbis feedback: Excludes ALL emails within HTML attribute values (src, data-*, href, value, title, etc.).

Latest Improvements

  1. Performance optimization: Both methods use precomputed tag ranges approach (O(n+m) instead of O(n*m) complexity)
  2. Robustness: Added checks for $_SERVER['REQUEST_METHOD'] and $_POST to avoid PHP notices in CLI contexts
  3. Consistency: Added whitelist checking to makeEmailClickable() for consistent behavior across all obfuscation methods
  4. Bug fixes: Removed redundant variables, restored retina pattern check for edge cases

Key Changes

  • Both methods now use precomputed HTML tag ranges for better performance
  • Safer $_SERVER access with isset() checks
  • Consistent whitelist handling across unicorn and clickable methods
  • Handles edge cases like < characters within attribute values

Benefits

Feature Pattern Exclusion Attribute Exclusion (This PR)
Fixes retina images
Fixes emails in form inputs
Fixes emails in data attributes
Fixes emails in ANY attributes
Performance optimized
Handles edge cases
Consistent whitelist support

Testing

✅ All 16 test cases passed:

  • Retina images preserved in attributes
  • Emails in attributes preserved
  • Emails in text correctly obfuscated
  • Edge case with < in attributes handled correctly
  • Both unicorn and clickable methods working correctly
  • Whitelist functionality consistent across both methods

Fixes FriendsOfREDAXO/emailobfuscator#50

Original prompt

This section details on the original issue you should resolve

<issue_title>"Erkennt" [email protected] als E-Mail</issue_title> <issue_description>Der Obfuscator erkennt [email protected] als E-Mail-Adresse und macht dies draus:

<img src="/Logo&lt;span class=unicorn&gt;&lt;span&gt;_at_&lt;/span&gt;&lt;/span&gt;2x.png" alt="Logo" class="img-fluid" loading="lazy">

REDAXO | 5.17.1 PHP: 8.1.33 E-Mail Obfuscator 3.0.0

Methode: ROT13 Einhorn-Markup (Standard, benötigt JQuery)</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes FriendsOfREDAXO/emailobfuscator#50


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Oct 15 '25 16:10 Copilot