Skip to content

[BUG] Resolves https://github.com/magento/magento2/issues/39002 #39038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Address/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public function isValid($value)
$messages['invalid_email_format'] = 'Invalid email format';
}

$pattern_name = '/(?:[\p{L}\p{M}\,\-\_\.\'’`\s\d]){1,255}+/u';
$messages = $this->isValidPattern($pattern_name, $value->getFirstname(), $messages, 'invalid_firstname', 'First Name is not valid!');
$messages = $this->isValidPattern($pattern_name, $value->getLastname(), $messages, 'invalid_lastname', 'Last Name is not valid!');
$messages = $this->isValidPattern($pattern_name, $value->getMiddlename(), $messages, 'invalid_middlename', 'Middle Name is not valid!');
$messages = $this->isValidPattern($pattern_name, $value->getCompany(), $messages, 'invalid_company', 'Company is not valid!');
$pattern_street = "/(?:[\p{L}\p{M}\"[],-.'’`&\s\d]){1,255}+/u";
foreach ($value->getStreet() as $street) {
$messages = $this->isValidPattern($pattern_street, $street, $messages, 'invalid_street', 'Street is not valid!');
}
$pattern_city = '/(?:[\p{L}\p{M}\s\-\']{1,100})/u';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

city field in the database accepts 255 signs, i not see why here they will be limited to random "100" symbols.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same must be applied to region field also.

Copy link

@IJOL IJOL Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola a todos:

I'm not xavi but i participate in the coding, we copied all patterns from #38345, you need to point the same there was accepted and is the originator of the bug you saw here, thanks for your help

$messages = $this->isValidPattern($pattern_city, $value->getCity(), $messages, 'invalid_city', 'City is not valid!');

$countryId = $value->getCountryId();
if (!empty($countryId)) {
$country = $this->countryFactory->create();
Expand All @@ -61,4 +73,24 @@ public function isValid($value)

return empty($messages);
}
/**
* @param string $pattern
* @param mixed $value
* @param array $messages
* @param $message_type
* @param $message
* @return array
*/
public function isValidPattern(string $pattern, mixed $value, array $messages, $message_type, $message): array
{
if ($value == null) {
return $messages;
}
if (preg_match($pattern, $value, $matches)) {
if ($matches[0] != $value) {
$messages[$message_type] = $message;
}
}
return $messages;
}
}