0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Issue 238 remove leading zeroes except if there is only zero (#239)

* Issue 238 remove leading zeroes except if there is only zero

* Issue-238 unit test fixes
This commit is contained in:
lubomirbartos 2019-11-21 16:05:07 +01:00 committed by Edward Z. Yang
parent 4faca32a4d
commit df923d1f15
6 changed files with 20 additions and 14 deletions

View File

@ -69,7 +69,13 @@ class HTMLPurifier_AttrDef_CSS_Number extends HTMLPurifier_AttrDef
return false;
}
$left = ltrim($left, '0');
// Remove leading zeros until positive number or a zero stays left
if (ltrim($left, '0') != '') {
$left = ltrim($left, '0');
} else {
$left = '0';
}
$right = rtrim($right, '0');
if ($right === '') {

View File

@ -9,7 +9,7 @@ class HTMLPurifier_AttrDef_CSS_AlphaValueTest extends HTMLPurifier_AttrDefHarnes
$this->assertDef('0');
$this->assertDef('1');
$this->assertDef('.2');
$this->assertDef('0.2');
// clamping to [0.0, 1,0]
$this->assertDef('1.2', '1');

View File

@ -17,7 +17,7 @@ class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarnes
);
$this->assertDef(
'rgba(74, 12, 85, 0.35) repeat fixed bottom',
'rgba(74,12,85,.35) repeat fixed bottom'
'rgba(74,12,85,0.35) repeat fixed bottom'
);
$this->assertDef(
'hsl(244, 47.4%, 88.1%) right center',

View File

@ -20,8 +20,8 @@ class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('rgb(12%,150%,0%)', 'rgb(12%,100%,0%)'); // percentage max values
$this->assertDef('rgba(255, 0, 0, 0)', 'rgba(255,0,0,0)'); // rm spaces
$this->assertDef('rgba(100%,0%,0%,.4)');
$this->assertDef('rgba(38.1%,59.7%,1.8%,0.7)', 'rgba(38.1%,59.7%,1.8%,.7)'); // decimals okay
$this->assertDef('rgba(100%,0%,0%,0.4)');
$this->assertDef('rgba(38.1%,59.7%,1.8%,0.7)', 'rgba(38.1%,59.7%,1.8%,0.7)'); // decimals okay
$this->assertDef('hsl(275, 45%, 81%)', 'hsl(275,45%,81%)'); // rm spaces
$this->assertDef('hsl(100,0%,0%)');
@ -30,8 +30,8 @@ class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('hsl(380,125%,0%)', 'hsl(360,100%,0%)'); // max values
$this->assertDef('hsla(100, 74%, 29%, 0)', 'hsla(100,74%,29%,0)'); // rm spaces
$this->assertDef('hsla(154,87%,21%,.4)');
$this->assertDef('hsla(45,94.3%,4.1%,0.7)', 'hsla(45,94.3%,4.1%,.7)'); // decimals okay
$this->assertDef('hsla(154,87%,21%,0.4)');
$this->assertDef('hsla(45,94.3%,4.1%,0.7)', 'hsla(45,94.3%,4.1%,0.7)'); // decimals okay
$this->assertDef('#G00', false);
$this->assertDef('cmyk(40, 23, 43, 23)', false);

View File

@ -12,8 +12,8 @@ class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('1.0', '1');
$this->assertDef('34');
$this->assertDef('4.5');
$this->assertDef('.5');
$this->assertDef('0.5', '.5');
$this->assertDef('0.5');
$this->assertDef('0.5', '0.5');
$this->assertDef('-56.9');
$this->assertDef('0.', '0');
@ -21,10 +21,10 @@ class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('0.0', '0');
$this->assertDef('1.', '1');
$this->assertDef('.1', '.1');
$this->assertDef('.1', '0.1');
$this->assertDef('1.0', '1');
$this->assertDef('0.1', '.1');
$this->assertDef('0.1', '0.1');
$this->assertDef('000', '0');
$this->assertDef(' 9', '9');

View File

@ -140,8 +140,8 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('scrollbar-highlight-color:#ff69b4;');
$this->assertDef('scrollbar-shadow-color:#f0f;');
$this->assertDef('-moz-opacity:.2;');
$this->assertDef('-khtml-opacity:.2;');
$this->assertDef('-moz-opacity:0.2;');
$this->assertDef('-khtml-opacity:0.2;');
$this->assertDef('filter:alpha(opacity=20);');
$this->assertDef('border-top-left-radius:55pt 25pt;');
@ -160,7 +160,7 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('display:none;');
$this->assertDef('visibility:visible;');
$this->assertDef('overflow:scroll;');
$this->assertDef('opacity:.2;');
$this->assertDef('opacity:0.2;');
}
public function testForbidden()