Upd. Contact encoder. Refactoring for the code duplication removing. - #5
Open
Glomberg wants to merge 11 commits into
Open
Upd. Contact encoder. Refactoring for the code duplication removing.#5Glomberg wants to merge 11 commits into
Glomberg wants to merge 11 commits into
Conversation
…balPhoneNumbers`.
…balPhoneNumbers`.
…ern_without_capturing` removed.
There was a problem hiding this comment.
Pull request overview
This PR refactors the ContactsEncoder implementation to reduce duplicated logic, primarily by removing PHP-version-specific branches and simplifying how match context is handled during global email/phone replacements.
Changes:
- Removed the unused
plain_email_pattern_without_capturingproperty and its corresponding test. - Consolidated
modifyGlobalEmails()/modifyGlobalPhoneNumbers()logic by removing PHP 7.4+ “V2” implementations and version branches. - Updated
ContactsEncoderHelperAPIs to accept plain strings instead ofPREG_OFFSET_CAPTUREmatch arrays.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
ContactsEncoder.php |
Removes version-specific callback branches and V2 link encoders; centralizes email/phone replacement logic. |
Helper/ContactsEncoderHelper.php |
Changes helper method signatures to accept email strings and uses strpos() to find positions. |
tests/ContactsEncoder/TestContactsEncoderPatterns.php |
Removes the test for the deleted regex property. |
Suppressed comments (1)
ContactsEncoder.php:378
isInsideScriptTag()is called with$matches[0][0], which is only the first character of the matched phone string. This makes the script-tag containment check unreliable.
// check if in script
if ( $this->helper->isInsideScriptTag($matches[0][0], $this->temp_content) ) {
return $matches[0];
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (4)
Helper/ContactsEncoderHelper.php:60
isMailtoAdditionalCopy()now derives the match position viastrpos($content, $email), which always returns the first occurrence. If the same email appears multiple times, later matches can be misclassified (e.g., if the first occurrence is incc=/bcc=but a later one isn’t, the later one will still be treated as an additional copy). This method needs the position of the current regex match (or an equivalent per-match offset) to be reliable.
public function isMailtoAdditionalCopy($email, $content)
{
$position = strpos($content, $email);
if ($position === false) {
return false;
}
ContactsEncoder.php:323
modifyGlobalEmails()now encodes any match containingmailto:by replacing just themailto:<email>substring with a string that injects" data-original-string=... title=".... This assumes the match is inside an HTML attribute value and is immediately followed by a closing quote. Ifmailto:appears in plain text, or if thehrefcontains query params (e.g.mailto:a@b.com?subject=Hi&cc=c@d.com), this replacement can corrupt the surrounding HTML/attribute structure.
if (
isset($matches[0]) && $this->helper->isMailtoAdditionalCopy($matches[0], $this->temp_content)
) {
return '';
}
if ( isset($matches[0]) && $this->helper->isMailto($matches[0]) ) {
return $this->encodeMailtoLink($matches[0]);
}
ContactsEncoder.php:355
modifyGlobalPhoneNumbers()encodes any match containingtel:by replacing just the matchedtel:+<digits>substring with a string that injects" data-original-string=... title=".... This assumes the match is inside anhrefattribute value and is immediately followed by a closing quote; iftel:appears in plain text (or any non-attribute context), the replacement will introduce stray quotes/attributes and can break markup.
if ( isset($matches[0]) ) {
if ( $this->helper->isTelTag($matches[0]) ) {
return $this->encodeTelLink($matches[0]);
}
Helper/ContactsEncoderHelper.php:50
- The docblock for
isMailtoAdditionalCopy()says it checks whether the string contains amailto:link, but the implementation actually checks whether the email is immediately preceded bycc=orbcc=in the content. Updating the docblock will prevent confusion for future maintainers.
/**
* Checking if the string contains mailto: link
*
* @param string $email
* @param string $content
AntonV1211
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://app.doboard.com/1/task/41418