Skip to content
Snippets Groups Projects
Unverified Commit 1a426c3b authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

gluon-web: make pcdata() prototype match lmo_translate()

parent 93d33939
No related branches found
No related tags found
No related merge requests found
...@@ -75,19 +75,16 @@ static int template_L_parse_string(lua_State *L) ...@@ -75,19 +75,16 @@ static int template_L_parse_string(lua_State *L)
static int template_L_pcdata(lua_State *L) static int template_L_pcdata(lua_State *L)
{ {
size_t len = 0, outlen; size_t inlen, outlen;
const char *str = luaL_checklstring(L, 1, &len); char *out;
char *res = pcdata(str, len, &outlen); const char *in = luaL_checklstring(L, 1, &inlen);
if (!pcdata(in, inlen, &out, &outlen))
return 0;
if (res != NULL) lua_pushlstring(L, out, outlen);
{ free(out);
lua_pushlstring(L, res, outlen);
free(res);
return 1; return 1;
}
return 0;
} }
static int template_L_load_catalog(lua_State *L) { static int template_L_load_catalog(lua_State *L) {
......
...@@ -256,7 +256,7 @@ static size_t validate_utf8(const unsigned char **s, size_t l, struct template_b ...@@ -256,7 +256,7 @@ static size_t validate_utf8(const unsigned char **s, size_t l, struct template_b
/* Sanitize given string and strip all invalid XML bytes /* Sanitize given string and strip all invalid XML bytes
* Validate UTF-8 sequences * Validate UTF-8 sequences
* Escape XML control chars */ * Escape XML control chars */
char * pcdata(const char *s, size_t l, size_t *outl) bool pcdata(const char *s, size_t l, char **out, size_t *outl)
{ {
struct template_buffer *buf = buf_init(l); struct template_buffer *buf = buf_init(l);
const unsigned char *ptr = (const unsigned char *)s; const unsigned char *ptr = (const unsigned char *)s;
...@@ -265,15 +265,14 @@ char * pcdata(const char *s, size_t l, size_t *outl) ...@@ -265,15 +265,14 @@ char * pcdata(const char *s, size_t l, size_t *outl)
int esl; int esl;
if (!buf) if (!buf)
return NULL; return false;
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)) ||
((*ptr >= 0x0E) && (*ptr <= 0x1F)) || ((*ptr >= 0x0E) && (*ptr <= 0x1F)) ||
(*ptr == 0x7F)) (*ptr == 0x7F)) {
{
ptr++; ptr++;
} }
...@@ -282,8 +281,7 @@ char * pcdata(const char *s, size_t l, size_t *outl) ...@@ -282,8 +281,7 @@ char * pcdata(const char *s, size_t l, size_t *outl)
(*ptr == '"') || (*ptr == '"') ||
(*ptr == '&') || (*ptr == '&') ||
(*ptr == '<') || (*ptr == '<') ||
(*ptr == '>')) (*ptr == '>')) {
{
esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
if (!buf_append(buf, esq, esl)) if (!buf_append(buf, esq, esl))
...@@ -293,14 +291,12 @@ char * pcdata(const char *s, size_t l, size_t *outl) ...@@ -293,14 +291,12 @@ char * pcdata(const char *s, size_t l, size_t *outl)
} }
/* ascii char */ /* ascii char */
else if (*ptr <= 0x7F) else if (*ptr <= 0x7F) {
{
buf_putchar(buf, (char)*ptr++); buf_putchar(buf, (char)*ptr++);
} }
/* multi byte sequence */ /* multi byte sequence */
else else {
{
if (!(v = validate_utf8(&ptr, l - o, buf))) if (!(v = validate_utf8(&ptr, l - o, buf)))
break; break;
...@@ -309,5 +305,6 @@ char * pcdata(const char *s, size_t l, size_t *outl) ...@@ -309,5 +305,6 @@ char * pcdata(const char *s, size_t l, size_t *outl)
} }
*outl = buf_length(buf); *outl = buf_length(buf);
return buf_destroy(buf); *out = buf_destroy(buf);
return true;
} }
...@@ -42,7 +42,6 @@ static inline size_t buf_length(const struct template_buffer *buf) ...@@ -42,7 +42,6 @@ static inline size_t buf_length(const struct template_buffer *buf)
return buf->dptr - buf->data; return buf->dptr - buf->data;
} }
bool pcdata(const char *s, size_t l, char **out, size_t *outl);
char * pcdata(const char *s, size_t l, size_t *outl);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment