Fix for nbsp in tag attribs

This commit is contained in:
Andrew Pamment 2018-10-22 17:16:10 +10:00
parent 3dab626285
commit fb09e38602

View File

@ -4,7 +4,7 @@
#include "www_tree.h" #include "www_tree.h"
#include "bbs.h" #include "bbs.h"
static char *www_tag_sanatize(char *data) { static char *www_tag_sanatize(char *data, int isdata) {
stralloc str = EMPTY_STRALLOC; stralloc str = EMPTY_STRALLOC;
for (char *p = data; *p != '\0'; ++p) { for (char *p = data; *p != '\0'; ++p) {
switch (*p) { switch (*p) {
@ -521,16 +521,20 @@ static char *www_tag_sanatize(char *data) {
stralloc_cats(&str, "▪"); stralloc_cats(&str, "▪");
break; break;
case ' ': case ' ':
if (*(p+1) == ' ') { if (isdata) {
stralloc_cats(&str, " "); if (*(p+1) == ' ') {
} else { stralloc_cats(&str, " ");
if (p > data && (*(p-1) == ' ' || *(p-1) == '\n')) {
stralloc_cats(&str, " ");
} else if (data == p) {
stralloc_cats(&str, " ");
} else { } else {
stralloc_append1(&str, ' '); if (p > data && (*(p-1) == ' ' || *(p-1) == '\n')) {
stralloc_cats(&str, " ");
} else if (data == p) {
stralloc_cats(&str, " ");
} else {
stralloc_append1(&str, ' ');
}
} }
} else {
stralloc_append1(&str, ' ');
} }
break; break;
@ -555,7 +559,7 @@ struct www_tag *www_tag_new(char *tag, char *data) {
new_tag->tag = NULL; new_tag->tag = NULL;
/* SANATIZE DATA HERE */ /* SANATIZE DATA HERE */
new_tag->data = www_tag_sanatize(data); new_tag->data = www_tag_sanatize(data, 1);
} else { } else {
new_tag->tag = strdup(tag); new_tag->tag = strdup(tag);
new_tag->data = NULL; new_tag->data = NULL;
@ -579,7 +583,7 @@ struct www_tag *www_tag_duplicate(struct www_tag *oldtag) {
void www_tag_add_attrib(struct www_tag *tag, char *attrib, char *value) { void www_tag_add_attrib(struct www_tag *tag, char *attrib, char *value) {
ptr_vector_append(&tag->attribs, strdup(attrib)); ptr_vector_append(&tag->attribs, strdup(attrib));
ptr_vector_append(&tag->values, www_tag_sanatize(value)); ptr_vector_append(&tag->values, www_tag_sanatize(value, 0));
} }
void www_tag_add_child(struct www_tag *tag, struct www_tag *child) { void www_tag_add_child(struct www_tag *tag, struct www_tag *child) {