gluon-web: use ' instead of " for strings in generated Lua code

We need a bit less escaping this way.
This commit is contained in:
Matthias Schiffer 2018-02-23 00:34:06 +01:00
parent 3e292ba06f
commit 933cc3d7d9
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
2 changed files with 17 additions and 20 deletions

View File

@ -73,12 +73,12 @@ struct template_parser {
/* leading and trailing code for different types */ /* leading and trailing code for different types */
static const char *const gen_code[][2] = { static const char *const gen_code[][2] = {
[T_TYPE_INIT] = {NULL, NULL}, [T_TYPE_INIT] = {NULL, NULL},
[T_TYPE_TEXT] = {"write(\"", "\")"}, [T_TYPE_TEXT] = {"write('", "')"},
[T_TYPE_COMMENT] = {NULL, NULL}, [T_TYPE_COMMENT] = {NULL, NULL},
[T_TYPE_EXPR] = {"write(tostring(", " or \"\"))"}, [T_TYPE_EXPR] = {"write(tostring(", " or ''))"},
[T_TYPE_INCLUDE] = {"include(\"", "\")"}, [T_TYPE_INCLUDE] = {"include('", "')"},
[T_TYPE_I18N] = {"write(\"", "\")"}, [T_TYPE_I18N] = {"write('", "')"},
[T_TYPE_I18N_RAW] = {"write(\"", "\")"}, [T_TYPE_I18N_RAW] = {"write('", "')"},
[T_TYPE_CODE] = {NULL, " "}, [T_TYPE_CODE] = {NULL, " "},
[T_TYPE_EOF] = {NULL, NULL}, [T_TYPE_EOF] = {NULL, NULL},
}; };

View File

@ -267,8 +267,7 @@ char * pcdata(const char *s, size_t l, size_t *outl)
if (!buf) if (!buf)
return NULL; return NULL;
for (o = 0; o < l; o++) for (o = 0; o < l; o++) {
{
/* Invalid XML bytes */ /* Invalid XML bytes */
if ((*ptr <= 0x08) || if ((*ptr <= 0x08) ||
((*ptr >= 0x0B) && (*ptr <= 0x0C)) || ((*ptr >= 0x0B) && (*ptr <= 0x0C)) ||
@ -279,11 +278,11 @@ char * pcdata(const char *s, size_t l, size_t *outl)
} }
/* Escapes */ /* Escapes */
else if ((*ptr == 0x26) || else if ((*ptr == '\'') ||
(*ptr == 0x27) || (*ptr == '"') ||
(*ptr == 0x22) || (*ptr == '&') ||
(*ptr == 0x3C) || (*ptr == '<') ||
(*ptr == 0x3E)) (*ptr == '>'))
{ {
esl = snprintf(esq, sizeof(esq), "&#%i;", *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]; char esq[8];
const char *ptr; const char *ptr;
for (ptr = s; ptr < (s + l); ptr++) for (ptr = s; ptr < (s + l); ptr++) {
{ switch (*ptr) {
switch (*ptr)
{
case '\\': case '\\':
buf_append(out, "\\\\", 2); buf_append(out, "\\\\", 2);
break; break;
case '"': case '\'':
if (escape_xml) if (escape_xml)
buf_append(out, "&#34;", 5); buf_append(out, "&#39;", 5);
else else
buf_append(out, "\\\"", 2); buf_append(out, "\\\'", 2);
break; break;
case '\n': case '\n':
buf_append(out, "\\n", 2); buf_append(out, "\\n", 2);
break; break;
case '\'': case '"':
case '&': case '&':
case '<': case '<':
case '>': case '>':