mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-14 10:37:03 +00:00
Finish up tel support
This commit is contained in:
parent
ef300f30bb
commit
ea6377a5a8
@ -25,5 +25,6 @@ URIScheme - needs to have callable generic checks
|
||||
mailto - doesn't validate emails, doesn't validate querystring
|
||||
news - doesn't validate opaque path
|
||||
nntp - doesn't constrain path
|
||||
tel - doesn't validate phone numbers, only allows characters '+', '1-9', and 'x'
|
||||
|
||||
vim: et sw=4 sts=4
|
||||
|
@ -28,8 +28,11 @@ class HTMLPurifier_URIScheme_tel extends HTMLPurifier_URIScheme
|
||||
$uri->host = null;
|
||||
$uri->port = null;
|
||||
|
||||
// Simplify phone number
|
||||
$uri->path = preg_replace('/(?!^\+)[^\dx]/', '', str_replace('X', 'x', $uri->path));
|
||||
|
||||
// Regex from: http://snipplr.com/view/11540/regex-for-tel-uris/
|
||||
return preg_match('/^tel:((?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;phone-context=(?:\+[\d().-]*\d[\d().-]*|(?:[a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*(?:[a-z]|[a-z][a-z0-9-]*[a-z0-9])))(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*(?:,(?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;phone-context=\+[\d().-]*\d[\d().-]*)(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*)*)$/', $uri->path) ? true : false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
|
||||
$this->assertDef('news:rec.alt');
|
||||
$this->assertDef('nntp://news.example.com/324234');
|
||||
$this->assertDef('mailto:bob@example.com');
|
||||
$this->assertDef('tel:+15555555555');
|
||||
}
|
||||
|
||||
public function testIntegrationWithPercentEncoder()
|
||||
|
@ -37,6 +37,11 @@ class HTMLPurifier_URIFilter_MakeAbsoluteTest extends HTMLPurifier_URIFilterHarn
|
||||
$this->assertFiltering('mailto:bob@example.com');
|
||||
}
|
||||
|
||||
public function testPreserveAltSchemeWithTel()
|
||||
{
|
||||
$this->assertFiltering('tel:+15555555555');
|
||||
}
|
||||
|
||||
public function testFilterIgnoreHTTPSpecialCase()
|
||||
{
|
||||
$this->assertFiltering('http:/', 'http://example.com/');
|
||||
|
@ -69,6 +69,14 @@ class HTMLPurifier_URIParserTest extends HTMLPurifier_Harness
|
||||
);
|
||||
}
|
||||
|
||||
public function testTelURI()
|
||||
{
|
||||
$this->assertParsing(
|
||||
'tel:+1 (555) 555-5555',
|
||||
'tel', null, null, null, '+15555555555', null, null
|
||||
);
|
||||
}
|
||||
|
||||
public function testIPv4Address()
|
||||
{
|
||||
$this->assertParsing(
|
||||
|
@ -172,6 +172,25 @@ class HTMLPurifier_URISchemeTest extends HTMLPurifier_URIHarness
|
||||
);
|
||||
}
|
||||
|
||||
public function test_tel_regular()
|
||||
{
|
||||
$this->assertValidation(
|
||||
'tel:+1 (555) 555-5555'
|
||||
);
|
||||
|
||||
$this->assertValidation(
|
||||
'tel:+15555555555'
|
||||
);
|
||||
|
||||
$this->assertValidation(
|
||||
'tel:+1-555-555-5555x123'
|
||||
);
|
||||
|
||||
$this->assertValidation(
|
||||
'tel:555-555-5555'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_data_png()
|
||||
{
|
||||
$this->assertValidation(
|
||||
|
Loading…
x
Reference in New Issue
Block a user