Skip to content

Commit

Permalink
Merge pull request #1335 from sjinks/tests
Browse files Browse the repository at this point in the history
Fix broken php-tests
  • Loading branch information
Phalcon committed Oct 4, 2013
2 parents 42a4f37 + b187af3 commit e932823
Show file tree
Hide file tree
Showing 19 changed files with 5,911 additions and 6,133 deletions.
6 changes: 3 additions & 3 deletions ext/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ PHP_METHOD(Phalcon_Filter, _sanitize){
* The 'email' filter uses the filter extension
*/
PHALCON_INIT_VAR(type);
ZVAL_LONG(type, 517);
ZVAL_LONG(type, 517); /* FILTER_SANITIZE_EMAIL */

PHALCON_INIT_VAR(quote);
ZVAL_STRING(quote, "'", 1);
Expand All @@ -270,7 +270,7 @@ PHP_METHOD(Phalcon_Filter, _sanitize){
* 'int' filter sanitizes a numeric input
*/
PHALCON_INIT_NVAR(type);
ZVAL_LONG(type, 519);
ZVAL_LONG(type, 519); /* FILTER_SANITIZE_NUMBER_INT */

PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p2(filtered, "filter_var", value, type);
Expand All @@ -279,7 +279,7 @@ PHP_METHOD(Phalcon_Filter, _sanitize){

if (PHALCON_IS_STRING(filter, "string")) {
PHALCON_INIT_NVAR(type);
ZVAL_LONG(type, 513);
ZVAL_LONG(type, 513); /* FILTER_SANITIZE_STRING */

PHALCON_INIT_NVAR(filtered);
phalcon_call_func_p2(filtered, "filter_var", value, type);
Expand Down
4 changes: 2 additions & 2 deletions ext/kernel/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int phalcon_array_isset_fetch(zval **fetched, const zval *arr, zval *index) {
return 0;
}

int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, char *index, uint index_length, unsigned long key) {
int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length, unsigned long key) {

zval **zv;

Expand All @@ -102,7 +102,7 @@ int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, char *inde
return 0;
}

int phalcon_array_isset_string_fetch(zval **fetched, zval *arr, char *index, uint index_length) {
int phalcon_array_isset_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length) {

return phalcon_array_isset_quick_string_fetch(fetched, arr, index, index_length, zend_inline_hash_func(index, index_length));
}
Expand Down
4 changes: 2 additions & 2 deletions ext/kernel/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

/** Combined isset/fetch */
int phalcon_array_isset_fetch(zval **fetched, const zval *arr, zval *index);
int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, char *index, uint index_length, unsigned long key);
int phalcon_array_isset_string_fetch(zval **fetched, zval *arr, char *index, uint index_length);
int phalcon_array_isset_quick_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length, unsigned long key);
int phalcon_array_isset_string_fetch(zval **fetched, zval *arr, const char *index, uint index_length);
int phalcon_array_isset_long_fetch(zval **fetched, zval *arr, unsigned long index);

/** Check for index existence */
Expand Down
112 changes: 75 additions & 37 deletions ext/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ static void phalcon_tag_get_escaper(zval **return_value_ptr, zval *params TSRMLS
{
zval *autoescape, *result = NULL;

if (phalcon_array_isset_string_fetch(&autoescape, params, SS("escape"))) {
phalcon_array_unset_string(&params, SS("escape"), PH_SEPARATE);
}
else {
if (!phalcon_array_isset_string_fetch(&autoescape, params, SS("escape"))) {
autoescape = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_autoEscape") TSRMLS_CC);
}

if (zend_is_true(autoescape)) {
phalcon_call_self_func_params(result, &result, NULL, SL("getescaperservice") TSRMLS_CC, 0);
phalcon_call_static_func_params(result, &result, SL("phalcon\\tag"), SL("getescaperservice") TSRMLS_CC, 0);
if (EG(exception)) {
assert(result == NULL);
}
Expand All @@ -104,11 +101,36 @@ static void phalcon_tag_get_escaper(zval **return_value_ptr, zval *params TSRMLS
*return_value_ptr = result;
}

static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC)
static zend_bool phalcon_tag_associative_only(HashTable *ht, void *pData, zend_hash_key *hash_key, void *pParam)
{
return hash_key->arKey && hash_key->nKeyLength;
}

PHALCON_STATIC void phalcon_tag_render_attributes(zval *code, zval *attributes TSRMLS_DC)
{
zval *escaper, *escaped = NULL;
zval *escaper, *escaped = NULL, *attrs;
zval **value;
HashPosition hp;
int i;

struct str_size_t {
const char *str;
uint size;
};

static const struct str_size_t order[9] = {
{ SS("type") },
{ SS("for") },
{ SS("src") },
{ SS("href") },
{ SS("action") },
{ SS("id") },
{ SS("name") },
{ SS("value") },
{ SS("class") },
};

assert(Z_TYPE_P(attributes) == IS_ARRAY);

PHALCON_MM_GROW();

Expand All @@ -120,13 +142,29 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC)
return;
}

PHALCON_INIT_VAR(attrs);
array_init_size(attrs, zend_hash_num_elements(Z_ARRVAL_P(attributes)));

for (i=0; i<sizeof(order)/sizeof(order[0]); ++i) {
if (phalcon_hash_find(Z_ARRVAL_P(attributes), order[i].str, order[i].size, (void**)&value) == SUCCESS) {
Z_ADDREF_PP(value);
add_assoc_zval_ex(attrs, order[i].str, order[i].size, *value);
}
}

zend_hash_merge_ex(Z_ARRVAL_P(attrs), Z_ARRVAL_P(attributes), (copy_ctor_func_t)zval_add_ref, sizeof(zval*), phalcon_tag_associative_only, NULL);

if (phalcon_array_isset_string(attrs, SS("escape"))) {
phalcon_array_unset_string(&attrs, SS("escape"), 0);
}

if (escaper) {
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attributes), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(attributes), (void**)&value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(attributes), &hp)
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attrs), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(attrs), (void**)&value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(attrs), &hp)
) {
zval key = phalcon_get_current_key_w(Z_ARRVAL_P(attributes), &hp);
zval key = phalcon_get_current_key_w(Z_ARRVAL_P(attrs), &hp);
if (Z_TYPE_P(&key) == IS_STRING) {
PHALCON_INIT_NVAR(escaped);
phalcon_call_method_p1(escaped, escaper, "escapehtmlattr", *value);
Expand All @@ -136,11 +174,11 @@ static void phalcon_tag_write_attributes(zval *code, zval *attributes TSRMLS_DC)
}
else {
for (
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attributes), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(attributes), (void**)&value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(attributes), &hp)
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attrs), &hp);
zend_hash_get_current_data_ex(Z_ARRVAL_P(attrs), (void**)&value, &hp) == SUCCESS;
zend_hash_move_forward_ex(Z_ARRVAL_P(attrs), &hp)
) {
zval key = phalcon_get_current_key_w(Z_ARRVAL_P(attributes), &hp);
zval key = phalcon_get_current_key_w(Z_ARRVAL_P(attrs), &hp);
if (Z_TYPE_P(&key) == IS_STRING) {
PHALCON_SCONCAT_SVSVS(code, " ", &key, "=\"", *value, "\"");
}
Expand Down Expand Up @@ -523,7 +561,7 @@ PHP_METHOD(Phalcon_Tag, linkTo){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<a", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -597,6 +635,7 @@ PHP_METHOD(Phalcon_Tag, _inputField){
*/
if (!phalcon_array_isset_string(params, SS("value"))) {
if (phalcon_array_isset_long_fetch(&value, params, 0)) {
Z_ADDREF_P(value); /* because of PHALCON_INIT_VAR() */
phalcon_array_update_string(&params, ISL(value), &value, PH_COPY);
}
}
Expand All @@ -615,7 +654,7 @@ PHP_METHOD(Phalcon_Tag, _inputField){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<input", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -714,7 +753,7 @@ PHP_METHOD(Phalcon_Tag, _inputFieldChecked){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<input", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand All @@ -736,41 +775,40 @@ PHP_METHOD(Phalcon_Tag, _inputFieldChecked){

static void phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAMETERS, const char* type, int as_value)
{
zval *parameters, *name;
zval *parameters, *field_type;

phalcon_fetch_params(0, 1, 0, &parameters);

MAKE_STD_ZVAL(name);
ZVAL_STRING(name, type, 1);
MAKE_STD_ZVAL(field_type);
ZVAL_STRING(field_type, type, 1);
Z_DELREF_P(field_type);

if (as_value) {
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 3, name, parameters, PHALCON_GLOBAL(z_true));
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 3, field_type, parameters, PHALCON_GLOBAL(z_true));
}
else {
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 2, name, parameters);
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 2, field_type, parameters);
}

if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}

zval_ptr_dtor(&name);
}

static void phalcon_tag_generic_field_checked(INTERNAL_FUNCTION_PARAMETERS, const char* type)
{
zval *parameters, *name;
zval *parameters, *field_type;

phalcon_fetch_params(0, 1, 0, &parameters);

MAKE_STD_ZVAL(name);
ZVAL_STRING(name, type, 1);
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfieldchecked") TSRMLS_CC, 2, name, parameters);
MAKE_STD_ZVAL(field_type);
ZVAL_STRING(field_type, type, 1);
Z_DELREF_P(field_type);

phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfieldchecked") TSRMLS_CC, 2, field_type, parameters);
if (return_value_ptr && EG(exception)) {
ALLOC_INIT_ZVAL(*return_value_ptr);
}

zval_ptr_dtor(&name);
}

/**
Expand Down Expand Up @@ -1196,7 +1234,7 @@ PHP_METHOD(Phalcon_Tag, textArea){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<textarea", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -1284,7 +1322,7 @@ PHP_METHOD(Phalcon_Tag, form){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<form", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -1473,7 +1511,7 @@ PHP_METHOD(Phalcon_Tag, stylesheetLink){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<link rel=\"stylesheet\"", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -1575,7 +1613,7 @@ PHP_METHOD(Phalcon_Tag, javascriptInclude){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<script", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -1660,7 +1698,7 @@ PHP_METHOD(Phalcon_Tag, image){
PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<img", 1);

phalcon_tag_write_attributes(code, params TSRMLS_CC);
phalcon_tag_render_attributes(code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down Expand Up @@ -1824,7 +1862,7 @@ PHP_METHOD(Phalcon_Tag, tagHtml){
PHALCON_INIT_VAR(local_code);
PHALCON_CONCAT_SV(local_code, "<", tag_name);

phalcon_tag_write_attributes(local_code, params TSRMLS_CC);
phalcon_tag_render_attributes(local_code, params TSRMLS_CC);
if (EG(exception)) {
PHALCON_MM_RESTORE();
return;
Expand Down
7 changes: 7 additions & 0 deletions ext/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
+------------------------------------------------------------------------+
*/

#ifndef PHALCON_TAG_H
#define PHALCON_TAG_H

void phalcon_tag_render_attributes(zval *code, zval *attributes TSRMLS_DC);

extern zend_class_entry *phalcon_tag_ce;

PHALCON_INIT_CLASS(Phalcon_Tag);
Expand Down Expand Up @@ -238,3 +243,5 @@ PHALCON_INIT_FUNCS(phalcon_tag_method_entry){
PHP_ME(Phalcon_Tag, tagHtmlClose, arginfo_phalcon_tag_taghtmlclose, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};

#endif /* PHALCON_TAG_H */
36 changes: 6 additions & 30 deletions ext/tag/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "kernel/exception.h"
#include "kernel/object.h"

#include "tag.h"

/**
* Phalcon\Tag\Select
*
Expand Down Expand Up @@ -68,11 +70,8 @@ PHP_METHOD(Phalcon_Tag_Select, selectField){

zval *parameters, *data = NULL, *params = NULL, *eol, *id = NULL, *name, *value = NULL;
zval *use_empty = NULL, *empty_value = NULL, *empty_text = NULL, *code;
zval *avalue = NULL, *key = NULL, *close_option, *options = NULL, *using;
zval *resultset_options, *array_options, *escaped;
HashTable *ah0;
HashPosition hp0;
zval **hd;
zval *close_option, *options = NULL, *using;
zval *resultset_options, *array_options;

PHALCON_MM_GROW();

Expand Down Expand Up @@ -156,35 +155,12 @@ PHP_METHOD(Phalcon_Tag_Select, selectField){

PHALCON_INIT_VAR(code);
ZVAL_STRING(code, "<select", 1);
if (Z_TYPE_P(params) == IS_ARRAY) {

phalcon_is_iterable(params, &ah0, &hp0, 0, 0);

PHALCON_INIT_VAR(escaped);

while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

PHALCON_GET_HKEY(key, ah0, hp0);
PHALCON_GET_HVALUE(avalue);

if (Z_TYPE_P(key) != IS_LONG) {
if (Z_TYPE_P(avalue) != IS_ARRAY) {
phalcon_htmlspecialchars(escaped, avalue, NULL, NULL TSRMLS_CC);
PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", escaped, "\"");
zval_dtor(escaped);
ZVAL_NULL(escaped);
}
}

zend_hash_move_forward_ex(ah0, &hp0);
}

}
phalcon_tag_render_attributes(code, params TSRMLS_CC);

PHALCON_SCONCAT_SV(code, ">", eol);

PHALCON_INIT_VAR(close_option);
PHALCON_CONCAT_SV(close_option, "</option>", eol);
ZVAL_STRING(close_option, "</option>" PHP_EOL, 1);
if (zend_is_true(use_empty)) {
/**
* Create an empty value
Expand Down
2 changes: 1 addition & 1 deletion ext/tests/issue-1190.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ $form->add(new \Phalcon\Forms\Element\Text("title"));
echo $form->render('title'), PHP_EOL;
?>
--EXPECT--
<input value="Hello &quot;world!&quot;" name="title" id="title" type="text" />
<input type="text" id="title" name="title" value="Hello &quot;world!&quot;" />
Loading

0 comments on commit e932823

Please sign in to comment.