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

[hotfix/ZF-11617] Zend_Filter_StripTags #285

Closed
wants to merge 2 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+16 −131
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

[hotfix/ZF-11617] Zend_Filter_StripTags

- recognise hypen as HTML5 attribute name
  • Loading branch information...
thomasweidner committed Jul 28, 2011
commit 8acaae103a398dbd360de0d32f74f1f50ba581d8
@@ -761,33 +761,7 @@ protected function _validate()
$validatorRule[self::PRESENCE] = $this->defaults[self::PRESENCE];
}
if (!isset($validatorRule[self::ALLOW_EMPTY])) {
$foundNotEmptyValidator = false;
foreach ($validatorRule as $rule) {
if ($rule === 'NotEmpty') {
$foundNotEmptyValidator = true;
// field may not be empty, we are ready
break 1;
}
// we must check if it is an object before using instanceof
if (!is_object($rule)) {
// it cannot be a NotEmpty validator, skip this one
continue;
}
if($rule instanceof Validator\NotEmpty) {
$foundNotEmptyValidator = true;
// field may not be empty, we are ready
break 1;
}
}
if (!$foundNotEmptyValidator) {
$validatorRule[self::ALLOW_EMPTY] = $this->defaults[self::ALLOW_EMPTY];
} else {
$validatorRule[self::ALLOW_EMPTY] = false;
}
$validatorRule[self::ALLOW_EMPTY] = $this->defaults[self::ALLOW_EMPTY];
}
if (!isset($validatorRule[self::MESSAGES])) {
@@ -317,7 +317,7 @@ protected function _filterTag($tag)
// If there are non-whitespace characters in the attribute string
if (strlen($tagAttributes)) {
// Parse iteratively for well-formed attributes
preg_match_all('/(\w+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
preg_match_all('/([\w-]+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
// Initialize valid attribute accumulator
$tagAttributes = '';
@@ -1859,109 +1859,6 @@ public function testNoNestedMessageArrays()
$this->assertFalse(is_array($messages['field1']['isEmpty']), 'oh oh, we may have got nested messages');
$this->assertTrue(isset($messages['field1']['isEmpty']), 'oh no, we not even got the normally expected messages');
}
/**
* If setAllowEmpty(true) is called, all fields are optional, but fields with
* a NotEmpty validator attached to them, should contain a non empty value.
*
* @group ZF-9289
*/
function testAllowEmptyTrueRespectsNotEmtpyValidators()
{
$data = array(
'field1' => 'foo',
'field2' => ''
);
$validators = array(
'field1' => array(
new Validator\NotEmpty(),
InputFilter::MESSAGES => array(
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
)
),
'field2' => array(
new Validator\NotEmpty()
)
);
$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'Ouch, the NotEmpty validators are ignored!');
$validators = array(
'field1' => array(
'Digits',
array('NotEmpty', 'integer'),
InputFilter::MESSAGES => array(
1 =>
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
),
),
);
$data = array(
'field1' => 0,
'field2' => ''
);
$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'Ouch, if the NotEmpty validator is not the first rule, the NotEmpty validators are ignored !');
// and now with a string 'NotEmpty' instead of an instance:
$validators = array(
'field1' => array(
'NotEmpty',
InputFilter::MESSAGES => array(
0 =>
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
),
),
);
$data = array(
'field1' => '',
'field2' => ''
);
$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'If the NotEmpty validator is a string, the NotEmpty validator is ignored !');
// and now with an array
$validators = array(
'field1' => array(
array('NotEmpty', 'integer'),
InputFilter::MESSAGES => array(
0 =>
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
),
),
);
$data = array(
'field1' => 0,
'field2' => ''
);
$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'If the NotEmpty validator is an array, the NotEmpty validator is ignored !');
}
}
} // end namespace declaration
@@ -615,4 +615,18 @@ public function testNotClosedHtmlCommentAtEndOfString()
$expected = 'text';
$this->assertEquals($expected, $this->_filter->filter($input));
}
/**
* @group ZF-11617
*/
public function testFilterCanAllowHyphenatedAttributeNames()
{
$input = '<li data-disallowed="no!" data-name="Test User" data-id="11223"></li>';
$expected = '<li data-name="Test User" data-id="11223"></li>';
$this->_filter->setTagsAllowed('li');
$this->_filter->setAttributesAllowed(array('data-id','data-name'));
$this->assertEquals($expected, $this->_filter->filter($input));
}
}
ProTip! Use n and p to navigate between commits in a pull request.