From e93328725cd3e781916dad6a7580cda541808c35 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Thu, 16 Jan 2020 16:23:53 +0800 Subject: [PATCH] improve str_expand_vars --- docs/changes.md | 1 + src/base/system_info.c | 14 ++++++++++---- src/tkc/str.c | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 55480ebd3..19a54c67f 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -3,6 +3,7 @@ * 修复 progressbar 类型问题(感谢尧燊提供补丁) * 修复 arm linux 编译问题(感谢俊杰提供补丁) * 完善 mledit/edit 文档 (感谢大恒提供补丁) + * 完善 str\_expand\_vars(感谢朝泽提供补丁) * 2020/01/15 * 点击鼠标右键触发 context menu 事件。 diff --git a/src/base/system_info.c b/src/base/system_info.c index bf32816c7..d9b1dd4da 100644 --- a/src/base/system_info.c +++ b/src/base/system_info.c @@ -280,13 +280,19 @@ ret_t system_info_set_device_pixel_ratio(system_info_t* info, float_t device_pix static ret_t system_info_eval_one(system_info_t* info, str_t* str, const char* expr, tk_visit_t on_expr_result, void* ctx) { - if (strchr(expr, '$') != NULL) { + bool_t not_schema = strstr(expr, STR_SCHEMA_FILE) == NULL && + strstr(expr, STR_SCHEMA_HTTP) == NULL && + strstr(expr, STR_SCHEMA_HTTPS) == NULL; + + if (not_schema && strchr(expr, '$') != NULL) { str_set(str, ""); - ENSURE(str_expand_vars(str, expr, OBJECT(info)) == RET_OK); - } else { - ENSURE(str_set(str, expr) == RET_OK); + + if (str_expand_vars(str, expr, OBJECT(info)) == RET_OK) { + return on_expr_result(ctx, str->str); + } } + ENSURE(str_set(str, expr) == RET_OK); return on_expr_result(ctx, str->str); } diff --git a/src/tkc/str.c b/src/tkc/str.c index ab6108e3a..d7c71dbc0 100644 --- a/src/tkc/str.c +++ b/src/tkc/str.c @@ -557,8 +557,9 @@ ret_t str_expand_vars(str_t* str, const char* src, const object_t* obj) { if (c == '$') { if (p[1] && p[2]) { p = expand_var(str, p + 2, obj); + } else { + return RET_BAD_PARAMS; } - continue; } else { str_append_char(str, c); p++;