N°4515 Fix default validation pattern for AttributeURL (#249)

URL containing ":" in their path were rejected. This caused problems with some URL from Alfresco or Sharepoint...
The default regexp used by AttributeURL was updated to avoid this.
Warning, check your config to see if you have any custom regexp configured (`url_validation_pattern` config parameter) !

Also a test was added to document the default regexp.
This commit is contained in:
Pierre Goiffon
2021-12-29 11:43:07 +01:00
committed by GitHub
parent ed12f98075
commit ffd0bbb1a4
4 changed files with 72 additions and 4 deletions

View File

@@ -854,10 +854,12 @@ class Config
'url_validation_pattern' => [
'type' => 'string',
'description' => 'Regular expression to validate/detect the format of an URL (URL attributes and Wiki formatting for Text attributes)',
'default' => '(https?|ftp)\://([a-zA-Z0-9+!*(),;?&=\$_.-]+(\:[a-zA-Z0-9+!*(),;?&=\$_.-]+)?@)?([a-zA-Z0-9-.]{3,})(\:[0-9]{2,5})?(/([a-zA-Z0-9%+\$_-]\.?)+)*/?(\?[a-zA-Z+&\$_.-][a-zA-Z0-9;:[\]@&%=+/\$_.-]*)?(#[a-zA-Z_.-][a-zA-Z0-9+\$_.-]*)?',
// SHEME.......... USER....................... PASSWORD.......................... HOST/IP........... PORT.......... PATH........................ GET............................................ ANCHOR............................
'default' => /** @lang RegExp */
'(https?|ftp)\://([a-zA-Z0-9+!*(),;?&=\$_.-]+(\:[a-zA-Z0-9+!*(),;?&=\$_.-]+)?@)?([a-zA-Z0-9-.]{3,})(\:[0-9]{2,5})?(/([a-zA-Z0-9:%+\$_-]\.?)+)*/?(\?[a-zA-Z+&\$_.-][a-zA-Z0-9;:[\]@&%=+/\$_.-]*)?(#[a-zA-Z_.-][a-zA-Z0-9+\$_.-]*)?',
// SCHEME....... USER....................... PASSWORD.......................... HOST/IP........... PORT.......... PATH......................... GET............................................ ANCHOR..........................
// Example: http://User:passWord@127.0.0.1:8888/patH/Page.php?arrayArgument[2]=something:blah20#myAnchor
// Origin of this regexp: http://www.php.net/manual/fr/function.preg-match.php#93824
// RegExp source: http://www.php.net/manual/fr/function.preg-match.php#93824
// Update with N°4515
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => true,
@@ -1600,6 +1602,16 @@ class Config
return $this->m_aSettings[$sPropCode]['value'];
}
/**
* @param string $sPropCode
*
* @return mixed
*/
public function GetDefault($sPropCode)
{
return $this->m_aSettings[$sPropCode]['default'];
}
/**
* Whether the $sPropCode parameter has a custom value or the default one.
*

View File

@@ -29,5 +29,4 @@ class AttributeDefTest extends ItopDataTestCase {
$this->assertEquals(["status" => "ENUM('active','inactive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"],
$aImportColumns);
}
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* @since 3.0.0 N°4515
* @used-by \Combodo\iTop\Test\UnitTest\Core\AttributeURLTest
*/
class AttributeURLDefaultPattern extends AttributeURL {
public function GetValidationPattern()
{
/** @noinspection OneTimeUseVariablesInspection */
$oConfig = utils::GetConfig();
return $oConfig->GetDefault('url_validation_pattern');
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Core;
use AttributeURLDefaultPattern;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
class AttributeURLTest extends ItopTestCase {
public function setUp()
{
parent::setUp();
require_once APPROOT.'core/attributedef.class.inc.php';
require_once APPROOT.'test/core/AttributeURLDefaultPattern.php';
}
/**
* @throws \Exception
* @dataProvider CheckFormatProvider
*/
public function testCheckFormat(string $sUrlValue, int $iExpectedResult): void
{
$oAttDefUrl = new AttributeURLDefaultPattern('myCode', ["target"=>'_blank', "allowed_values"=>null, "sql"=>'url', "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array(), "always_load_in_tables"=>false]);
$bResult = $oAttDefUrl->CheckFormat($sUrlValue);
$this->assertSame($iExpectedResult, $bResult);
}
public function CheckFormatProvider(): array
{
return [
'Simple https URL' => ['https://www.combodo.com/itop', 1],
'Simple FTP URL' => ['ftp://user:password@myftp.mydomain.com', 1],
'Sharepoint URL 1' => ['https://mydomain1.sharepoint.com/:i:/r/sites/DSIMyDept/Shared%20Documents/Architecture%20Technique/02%20-%20R%C3%A9seau/Baie%2025C/Baie%201er/Baie-25C-1er.jpg?csf=1&web=1&e=Il3txR', 1],
'Sharepoint URL 2' => ['https://mydomain2.sharepoint.com/:u:/r/sites/DIS/ITSM/00_Admin_iTOP/iTop%20-%20Upgrade%20manuel/Procedure%20upgrade%20Combodo.url?csf=1&web=1&e=DAF0i3', 1],
'Alfresco URL 2' => ['http://alfresco.mydomain3.org/share/page/site/books/document-details?nodeRef=workspace://SpacesStore/6274f55f-a25b-4762-a863-77f7066f2034', 1],
];
}
}