diff --git a/package/gluon-web/src/template_parser.c b/package/gluon-web/src/template_parser.c index a0efcf4d..b69a99b3 100644 --- a/package/gluon-web/src/template_parser.c +++ b/package/gluon-web/src/template_parser.c @@ -73,12 +73,12 @@ struct template_parser { /* leading and trailing code for different types */ static const char *const gen_code[][2] = { [T_TYPE_INIT] = {NULL, NULL}, - [T_TYPE_TEXT] = {"write(\"", "\")"}, + [T_TYPE_TEXT] = {"write('", "')"}, [T_TYPE_COMMENT] = {NULL, NULL}, - [T_TYPE_EXPR] = {"write(tostring(", " or \"\"))"}, - [T_TYPE_INCLUDE] = {"include(\"", "\")"}, - [T_TYPE_I18N] = {"write(\"", "\")"}, - [T_TYPE_I18N_RAW] = {"write(\"", "\")"}, + [T_TYPE_EXPR] = {"write(tostring(", " or ''))"}, + [T_TYPE_INCLUDE] = {"include('", "')"}, + [T_TYPE_I18N] = {"write('", "')"}, + [T_TYPE_I18N_RAW] = {"write('", "')"}, [T_TYPE_CODE] = {NULL, " "}, [T_TYPE_EOF] = {NULL, NULL}, }; diff --git a/package/gluon-web/src/template_utils.c b/package/gluon-web/src/template_utils.c index 5f4211fc..7bd0f709 100644 --- a/package/gluon-web/src/template_utils.c +++ b/package/gluon-web/src/template_utils.c @@ -267,8 +267,7 @@ char * pcdata(const char *s, size_t l, size_t *outl) if (!buf) return NULL; - for (o = 0; o < l; o++) - { + for (o = 0; o < l; o++) { /* Invalid XML bytes */ if ((*ptr <= 0x08) || ((*ptr >= 0x0B) && (*ptr <= 0x0C)) || @@ -279,11 +278,11 @@ char * pcdata(const char *s, size_t l, size_t *outl) } /* Escapes */ - else if ((*ptr == 0x26) || - (*ptr == 0x27) || - (*ptr == 0x22) || - (*ptr == 0x3C) || - (*ptr == 0x3E)) + else if ((*ptr == '\'') || + (*ptr == '"') || + (*ptr == '&') || + (*ptr == '<') || + (*ptr == '>')) { esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); @@ -319,26 +318,24 @@ void luastr_escape(struct template_buffer *out, const char *s, size_t l, bool es char esq[8]; const char *ptr; - for (ptr = s; ptr < (s + l); ptr++) - { - switch (*ptr) - { + for (ptr = s; ptr < (s + l); ptr++) { + switch (*ptr) { case '\\': buf_append(out, "\\\\", 2); break; - case '"': + case '\'': if (escape_xml) - buf_append(out, """, 5); + buf_append(out, "'", 5); else - buf_append(out, "\\\"", 2); + buf_append(out, "\\\'", 2); break; case '\n': buf_append(out, "\\n", 2); break; - case '\'': + case '"': case '&': case '<': case '>':