Fix email obfuscator by skipping emails in HTML attributes
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
- Performance optimization: Both methods use precomputed tag ranges approach (O(n+m) instead of O(n*m) complexity)
-
Robustness: Added checks for
$_SERVER['REQUEST_METHOD']and$_POSTto avoid PHP notices in CLI contexts -
Consistency: Added whitelist checking to
makeEmailClickable()for consistent behavior across all obfuscation methods - 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
$_SERVERaccess withisset()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<span class=unicorn><span>_at_</span></span>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.