Skip to content

Commit

Permalink
Merge pull request #1271 from sjinks/issue-1263
Browse files Browse the repository at this point in the history
[1.3.0] Fix #1263
  • Loading branch information
Phalcon committed Sep 23, 2013
2 parents edaab95 + 0aa63b3 commit 731f242
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 354 deletions.
511 changes: 185 additions & 326 deletions ext/tag.c

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions ext/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ PHP_METHOD(Phalcon_Tag, setDI);
PHP_METHOD(Phalcon_Tag, getDI);
PHP_METHOD(Phalcon_Tag, getUrlService);
PHP_METHOD(Phalcon_Tag, getEscaperService);
PHP_METHOD(Phalcon_Tag, getAutoescape);
PHP_METHOD(Phalcon_Tag, setAutoescape);
PHP_METHOD(Phalcon_Tag, setDefault);
PHP_METHOD(Phalcon_Tag, setDefaults);
PHP_METHOD(Phalcon_Tag, displayTo);
PHP_METHOD(Phalcon_Tag, hasValue);
PHP_METHOD(Phalcon_Tag, getValue);
PHP_METHOD(Phalcon_Tag, resetInput);
Expand Down Expand Up @@ -82,11 +82,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_setdefaults, 0, 0, 1)
ZEND_ARG_INFO(0, values)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_displayto, 0, 0, 2)
ZEND_ARG_INFO(0, id)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_hasvalue, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -222,10 +217,11 @@ PHALCON_INIT_FUNCS(phalcon_tag_method_entry){
PHP_ME(Phalcon_Tag, getDI, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getUrlService, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getEscaperService, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getAutoescape, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setAutoescape, arginfo_phalcon_tag_setautoescape, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setDefault, arginfo_phalcon_tag_setdefault, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setDefaults, arginfo_phalcon_tag_setdefaults, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, displayTo, arginfo_phalcon_tag_displayto, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_MALIAS(Phalcon_Tag, displayTo, setDefault, arginfo_phalcon_tag_setdefault, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, hasValue, arginfo_phalcon_tag_hasvalue, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getValue, arginfo_phalcon_tag_getvalue, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, resetInput, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
Expand Down
3 changes: 2 additions & 1 deletion ext/tests/issue-1190.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Form.render doesn't escape value attributes on TextFields - https://github.com/p
<?php include('skipif.inc'); ?>
--FILE--
<?php
new \Phalcon\DI\FactoryDefault();
$object = new stdClass();
$object->title = 'Hello "world!"';
$form = new \Phalcon\Forms\Form($object);
$form->add(new \Phalcon\Forms\Element\Text("title"));
echo $form->render('title'), PHP_EOL;
?>
--EXPECT--
<input type="text" value="Hello &quot;world!&quot;" name="title" id="title" />
<input value="Hello &quot;world!&quot;" name="title" id="title" type="text" />
10 changes: 5 additions & 5 deletions ext/tests/issue-1216.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ $di = new \Phalcon\DI\FactoryDefault();
$e = new \Phalcon\Forms\Element\Text('TEXT');
echo $e->label(array('id' => 'test<', 'class' => 'test>')), PHP_EOL;
echo \Phalcon\Tag::linkTo(array('url"', '<>', 'class' => 'class"')), PHP_EOL;
echo \Phalcon\Tag::textField(array('name"')), PHP_EOL;
echo \Phalcon\Tag::checkField(array('name"')), PHP_EOL;
echo \Phalcon\Tag::textField(array('name"', 'class' => 'class"')), PHP_EOL;
echo \Phalcon\Tag::checkField(array('name"', 'class' => 'class"')), PHP_EOL;
echo \Phalcon\Tag::form(array('<', 'method' => '>')), PHP_EOL;
echo \Phalcon\Tag::textArea(array('<', 'cols' => '<')), PHP_EOL;
echo \Phalcon\Tag::stylesheetLink(array('href' => '<', 'local' => false, 'type' => '>')), PHP_EOL;
Expand All @@ -21,9 +21,9 @@ echo "DONE", PHP_EOL;
?>
--EXPECT--
<label for="test&lt;" id="test&lt;" class="test&gt;">test<</label>
<a href="/tests/url&quot;" class="class&quot;"><></a>
<input type="text" name="name&quot;" id="name&quot;" value="" />
<input type="checkbox" name="name&quot;" id="name&quot;" value="" />
<a class="class&quot;" href="/tests/url&quot;"><></a>
<input class="class&quot;" name="name&quot;" id="name&quot;" value="" type="text" />
<input class="class&quot;" name="name&quot;" id="name&quot;" value="" type="checkbox" />
<form method="&gt;" action="/tests/&lt;">
<textarea cols="&lt;" name="&lt;" id="&lt;"></textarea>
<link rel="stylesheet" href="&lt;" type="&gt;" />
Expand Down
35 changes: 35 additions & 0 deletions ext/tests/issue-1263.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Inconsistent behavior of Phalcon\Tag::setAutoescape() - https://github.com/phalcon/cphalcon/issues/1263
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
new \Phalcon\DI\FactoryDefault();

var_dump(\Phalcon\Tag::getAutoescape());

\Phalcon\Tag::setAutoescape(false);
var_dump(\Phalcon\Tag::getAutoescape());
echo \Phalcon\Tag::textField(array('name', 'value' => '&"')), PHP_EOL;

\Phalcon\Tag::setAutoescape(true);
var_dump(\Phalcon\Tag::getAutoescape());
echo \Phalcon\Tag::textField(array('name', 'value' => '&"')), PHP_EOL;

\Phalcon\Tag::setAutoescape(false);
\Phalcon\Tag::setDefault('name', '&"');
echo \Phalcon\Tag::textField(array('name')), PHP_EOL;

\Phalcon\Tag::setAutoescape(true);
\Phalcon\Tag::setDefault('name', '&"');
echo \Phalcon\Tag::textField(array('name')), PHP_EOL;
?>
--EXPECT--
bool(true)
bool(false)
<input value="&"" name="name" id="name" type="text" />
bool(true)
<input value="&amp;&quot;" name="name" id="name" type="text" />
<input name="name" id="name" value="&"" type="text" />
<input name="name" id="name" value="&amp;&quot;" type="text" />

6 changes: 3 additions & 3 deletions ext/tests/issue-947.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ echo \Phalcon\Tag::radioField(array('test', 'value' => 0)), PHP_EOL;
echo \Phalcon\Tag::radioField(array('test', 'value' => 0)), PHP_EOL;
?>
--EXPECT--
<input type="radio" value="1" checked="checked" name="test" id="test" />
<input type="radio" value="0" name="test" id="test" />
<input type="radio" value="0" name="test" id="test" checked="checked" />
<input checked="checked" name="test" id="test" value="1" type="radio" />
<input name="test" id="test" value="0" type="radio" />
<input name="test" id="test" checked="checked" value="0" type="radio" />
18 changes: 9 additions & 9 deletions unit-tests/FormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public function testFormElementRender()
$element1 = new Text("name");
$element1->setAttributes(array('class' => 'big-input'));

$this->assertEquals($element1->render(), '<input type="text" class="big-input" name="name" id="name" value="" />');
$this->assertEquals((string) $element1, '<input type="text" class="big-input" name="name" id="name" value="" />');
$this->assertEquals($element1->render(), '<input class="big-input" name="name" id="name" value="" type="text" />');
$this->assertEquals((string) $element1, '<input class="big-input" name="name" id="name" value="" type="text" />');
}

public function testForm()
Expand All @@ -190,8 +190,8 @@ public function testFormIndirectElementRender()

$form->add(new Text("name"));

$this->assertEquals($form->render('name'), '<input type="text" name="name" id="name" value="" />');
$this->assertEquals($form->render('name', array('class' => 'big-input')), '<input type="text" class="big-input" name="name" id="name" value="" />');
$this->assertEquals($form->render('name'), '<input name="name" id="name" value="" type="text" />');
$this->assertEquals($form->render('name', array('class' => 'big-input')), '<input class="big-input" name="name" id="name" value="" type="text" />');
}

public function testFormLabels()
Expand Down Expand Up @@ -331,8 +331,8 @@ public function testFormRenderEntity()
$form->add($address);
$form->add($telephone);

$this->assertEquals($form->render('address'), '<input type="text" value="Cr. 12 #12-82" name="address" id="address" />');
$this->assertEquals($form->render('telephone'), '<input type="text" value="+44 124 82122" name="telephone" id="telephone" />');
$this->assertEquals($form->render('address'), '<input value="Cr. 12 #12-82" name="address" id="address" type="text" />');
$this->assertEquals($form->render('telephone'), '<input value="+44 124 82122" name="telephone" id="telephone" type="text" />');
}

public function testFormRenderEntityGetters()
Expand All @@ -355,8 +355,8 @@ public function testFormRenderEntityGetters()
$form->add($address);
$form->add($telephone);

$this->assertEquals($form->render('address'), '<input type="text" value="Cr. 12 #12-82" name="address" id="address" />');
$this->assertEquals($form->render('telephone'), '<input type="text" value="+44 124 82122" name="telephone" id="telephone" />');
$this->assertEquals($form->render('address'), '<input value="Cr. 12 #12-82" name="address" id="address" type="text" />');
$this->assertEquals($form->render('telephone'), '<input value="+44 124 82122" name="telephone" id="telephone" type="text" />');
}

public function testFormValidatorEntity()
Expand Down Expand Up @@ -473,7 +473,7 @@ public function testIssue1190()
$form = new Phalcon\Forms\Form($object);
$form->add(new Phalcon\Forms\Element\Text("title"));
$actual = $form->render('title');
$expected = '<input type="text" value="Hello &quot;world!&quot;" name="title" id="title" />';
$expected = '<input value="Hello &quot;world!&quot;" name="title" id="title" type="text" />';
$this->assertEquals($actual, $expected);
}

Expand Down
6 changes: 3 additions & 3 deletions unit-tests/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ public function testIssue1216()
$di = new \Phalcon\DI\FactoryDefault();

$actual = \Phalcon\Tag::linkTo(array('url"', '<>', 'class' => 'class"'));
$expected = '<a href="/url&quot;" class="class&quot;"><></a>';
$expected = '<a class="class&quot;" href="/url&quot;"><></a>';
$this->assertEquals($expected, $actual);

$actual = \Phalcon\Tag::textField(array('name"'));
$expected = '<input type="text" name="name&quot;" id="name&quot;" value="" />';
$expected = '<input name="name&quot;" id="name&quot;" value="" type="text" />';
$this->assertEquals($expected, $actual);

$actual = \Phalcon\Tag::checkField(array('name"'));
$expected = '<input type="checkbox" name="name&quot;" id="name&quot;" value="" />';
$expected = '<input name="name&quot;" id="name&quot;" value="" type="checkbox" />';
$this->assertEquals($expected, $actual);

$actual = \Phalcon\Tag::form(array('<', 'method' => '>'));
Expand Down

0 comments on commit 731f242

Please sign in to comment.