fix(xml): pass raw # if there's no constant name (#9418)

This commit is contained in:
André Costa
2026-01-08 00:27:49 +01:00
committed by GitHub
parent 62907621fb
commit 7db7f149c7
2 changed files with 19 additions and 0 deletions
+4
View File
@@ -794,6 +794,10 @@ static void resolve_consts(const char ** item_attrs, lv_xml_component_scope_t *
if(lv_streq(name, "styles")) continue; /*Styles will handle it themselves*/
if(value[0] == '#') {
const char * value_clean = &value[1];
/* if there's no constant value, we keep `#` as is */
if(*value_clean == '\0') {
continue;
}
const char * const_value = lv_xml_get_const(scope, value_clean);
if(const_value) {
@@ -365,4 +365,19 @@ void test_xml_complex(void)
TEST_ASSERT_EQUAL_SCREENSHOT("xml/complex_1.png");
}
void test_xml_label_pound_sign_gets_rendered_properly(void)
{
const char * my_screen =
"<screen>"
"<view>"
"<lv_label align=\"center\" text=\"#\"/>"
"</view>"
"</screen>";
lv_xml_register_component_from_data("screen", my_screen);
lv_obj_t * scr = lv_xml_create_screen("screen");
lv_screen_load(scr);
lv_obj_t * label = lv_obj_get_child(scr, 0);
TEST_ASSERT(lv_streq("#", lv_label_get_text(label)));
}
#endif