Skip to content

Commit 616a8a7

Browse files
committed
Add URL check for homepage
1 parent 8b4bbad commit 616a8a7

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/Phpbb/TranslationValidator/Validator/FileValidator.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,15 @@ public function validateJsonFile($originFile)
573573
{
574574
$this->output->addMessage(Output::FATAL, 'Name should start with phpbb/phpbb-language- followed by the language iso code', $originFile);
575575
}
576-
577-
if (!array_key_exists('description', $jsonContent))
576+
// Check for an existing description
577+
if (!array_key_exists('description', $jsonContent) || $jsonContent['description'] == '')
578+
{
579+
$this->output->addMessage(Output::FATAL, 'Description is missing', $originFile);
580+
}
581+
// Check if the description contains only words and punctuation, not URLs.
582+
elseif (preg_match('/\b(?:www|https)\b|(?:\.[a-z]{2,})/i', $jsonContent['description']))
578583
{
579-
$this->output->addMessage(Output::FATAL, 'File must contain a description value', $originFile);
584+
$this->output->addMessage(Output::FATAL, 'The description should only contain words - no URLs.', $originFile);
580585
}
581586
// Check if the type is correctly defined
582587
if ($jsonContent['type'] != 'phpbb-language')
@@ -597,9 +602,9 @@ public function validateJsonFile($originFile)
597602
$this->output->addMessage(Output::FATAL, 'The defined version is in the wrong format.', $originFile);
598603
}
599604
// Homepage should be at least an empty string
600-
if (!array_key_exists('homepage', $jsonContent))
605+
if (!preg_match('/(?:https?:\/\/|www\.)[^\s]+|(?:\b[a-z0-9-]+\.(?:com|net|org|info|io|co|biz|me|xyz|ai|app|dev|tech|tv|us|uk|de|fr|ru|jp|cn|in)\b)/i', $jsonContent['homepage']) && $jsonContent['homepage'] != '')
601606
{
602-
$this->output->addMessage(Output::FATAL, 'The homepage value is missing, can be an empty string.', $originFile);
607+
$this->output->addMessage(Output::FATAL, 'The homepage value allows only URLs or can be left empty.', $originFile);
603608
}
604609
// Check for the correct license value
605610
if ($jsonContent['license'] != 'GPL-2.0-only')

0 commit comments

Comments
 (0)