Skip to content
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

Regression in #1969 #2065

Closed
sergeyklay opened this issue Mar 11, 2020 · 4 comments
Closed

Regression in #1969 #2065

sergeyklay opened this issue Mar 11, 2020 · 4 comments
Assignees
Labels

Comments

@sergeyklay
Copy link
Contributor

let e = "\e"

is escaped now

-ZVAL_STRING(&e, "\e");		
+ZVAL_STRING(&e, "\\e");

so colors in ice console stopped working
https://github.com/ice/framework/blob/3667503adc7efb128ed8d56e46b0ef9b0e24577e/build/php7/ice/cli/console.zep.c#L289

Originally posted by @mruz in #1969 (comment)

@sergeyklay sergeyklay added the bug label Mar 11, 2020
@sergeyklay
Copy link
Contributor Author

@AlexNDRmac Could you please take a look

@AlexNDRmac
Copy link
Member

AlexNDRmac commented Mar 13, 2020

@mruz could you please check branch with fix

I've regenerated your part of code with this fix... and it LGTM :)

/**
 * Returns the given text with the correct color codes for a foreground and optionally a background color.
 * Colors: black, red, green, yellow, blue, magenta, cyan, lightgray, white*
 *
 * @param string text The text to color
 * @param string color The foreground color
 * @param int decoration Formatting type
 * @param string bgColor The background color
 * @return string Coded string
 */
PHP_METHOD(Test_Issues_Issue2065, color) {

	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
	zend_long decoration;
	zval *text_param = NULL, *color_param = NULL, *decoration_param = NULL, *bgColor_param = NULL, colors, bgColors, colored, e, foreground, background, _0, _1, _2$$3;
	zval text, color, bgColor;
	zval *this_ptr = getThis();

	ZVAL_UNDEF(&text);
	ZVAL_UNDEF(&color);
	ZVAL_UNDEF(&bgColor);
	ZVAL_UNDEF(&colors);
	ZVAL_UNDEF(&bgColors);
	ZVAL_UNDEF(&colored);
	ZVAL_UNDEF(&e);
	ZVAL_UNDEF(&foreground);
	ZVAL_UNDEF(&background);
	ZVAL_UNDEF(&_0);
	ZVAL_UNDEF(&_1);
	ZVAL_UNDEF(&_2$$3);

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 3, &text_param, &color_param, &decoration_param, &bgColor_param);

	zephir_get_strval(&text, text_param);
	if (!color_param) {
		ZEPHIR_INIT_VAR(&color);
		ZVAL_STRING(&color, "");
	} else {
		zephir_get_strval(&color, color_param);
	}
	if (!decoration_param) {
		decoration = 0;
	} else {
		decoration = zephir_get_intval(decoration_param);
	}
	if (!bgColor_param) {
		ZEPHIR_INIT_VAR(&bgColor);
		ZVAL_STRING(&bgColor, "");
	} else {
		zephir_get_strval(&bgColor, bgColor_param);
	}


	ZEPHIR_INIT_VAR(&colors);
	zephir_create_array(&colors, 9, 0);
	add_assoc_stringl_ex(&colors, SL("black"), SL("30"));
	add_assoc_stringl_ex(&colors, SL("red"), SL("31"));
	add_assoc_stringl_ex(&colors, SL("green"), SL("32"));
	add_assoc_stringl_ex(&colors, SL("yellow"), SL("33"));
	add_assoc_stringl_ex(&colors, SL("blue"), SL("34"));
	add_assoc_stringl_ex(&colors, SL("magenta"), SL("35"));
	add_assoc_stringl_ex(&colors, SL("cyan"), SL("36"));
	add_assoc_stringl_ex(&colors, SL("lightgray"), SL("37"));
	add_assoc_stringl_ex(&colors, SL("white"), SL("97"));
	ZEPHIR_INIT_VAR(&bgColors);
	zephir_create_array(&bgColors, 9, 0);
	add_assoc_stringl_ex(&bgColors, SL("black"), SL("40"));
	add_assoc_stringl_ex(&bgColors, SL("red"), SL("41"));
	add_assoc_stringl_ex(&bgColors, SL("green"), SL("42"));
	add_assoc_stringl_ex(&bgColors, SL("yellow"), SL("43"));
	add_assoc_stringl_ex(&bgColors, SL("blue"), SL("44"));
	add_assoc_stringl_ex(&bgColors, SL("magenta"), SL("45"));
	add_assoc_stringl_ex(&bgColors, SL("cyan"), SL("46"));
	add_assoc_stringl_ex(&bgColors, SL("lightgray"), SL("47"));
	add_assoc_stringl_ex(&bgColors, SL("white"), SL("107"));
	zephir_array_isset_fetch(&foreground, &colors, &color, 1);
	zephir_array_isset_fetch(&background, &bgColors, &bgColor, 1);
	ZEPHIR_INIT_VAR(&e);
	ZVAL_STRING(&e, "\e");
	ZEPHIR_INIT_VAR(&_0);
	ZVAL_LONG(&_0, decoration);
	ZEPHIR_INIT_VAR(&_1);
	if (zephir_is_true(&foreground)) {
		ZEPHIR_INIT_NVAR(&_1);
		ZEPHIR_CONCAT_SV(&_1, ";", &foreground);
	} else {
		ZEPHIR_INIT_NVAR(&_1);
		ZVAL_STRING(&_1, "");
	}
	ZEPHIR_INIT_VAR(&colored);
	ZEPHIR_CONCAT_VSVVS(&colored, &e, "[", &_0, &_1, "m");
	if (zephir_is_true(&background)) {
		ZEPHIR_INIT_VAR(&_2$$3);
		ZEPHIR_CONCAT_VSVS(&_2$$3, &e, "[", &background, "m");
		zephir_concat_self(&colored, &_2$$3);
	}
	ZEPHIR_CONCAT_VVVS(return_value, &colored, &text, &e, "[0m");
	RETURN_MM();

}

@mruz
Copy link
Contributor

mruz commented Mar 13, 2020

It works! Thanks @AlexNDRmac

@sergeyklay
Copy link
Contributor Author

Fixed in the development branch. Feel free to open a new issue if the problem appears again. Thank you for the bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants