HTML: Better quoting to the export strings

Move the quote function to membuffer.c and adding wrappers that call
it from both xml and html exporters to get rid of redundancy.

Quote the location, buddy, suit, tags and notes This
prevents js code from crashing.

[Miika Turkia: minor whitespace and code fix]

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2014-06-02 20:10:54 +03:00 committed by Dirk Hohndel
parent 1120379b2b
commit 464a611d8d
6 changed files with 73 additions and 104 deletions

View file

@ -96,7 +96,7 @@ void put_vformat(struct membuffer *b, const char *fmt, va_list args)
return;
}
room = len+1;
room = len + 1;
}
}
@ -174,5 +174,57 @@ void put_degrees(struct membuffer *b, degrees_t value, const char *pre, const ch
udeg = -udeg;
sign = "-";
}
put_format(b,"%s%s%u.%06u%s", pre, sign, FRACTION(udeg, 1000000), post);
put_format(b, "%s%s%u.%06u%s", pre, sign, FRACTION(udeg, 1000000), post);
}
void put_quoted(struct membuffer *b, const char *text, int is_attribute, int is_html)
{
const char *p = text;
for (;;) {
const char *escape;
switch (*p++) {
default:
continue;
case 0:
escape = NULL;
break;
case 1 ... 8:
case 11:
case 12:
case 14 ... 31:
escape = "?";
break;
case '<':
escape = "&lt;";
break;
case '>':
escape = "&gt;";
break;
case '&':
escape = "&amp;";
break;
case '\'':
if (!is_attribute)
continue;
escape = "&apos;";
break;
case '\"':
if (!is_attribute)
continue;
escape = "&quot;";
break;
case '\n':
if (!is_html)
continue;
else
escape = "<br>";
}
put_bytes(b, text, (p - text - 1));
if (!escape)
break;
put_string(b, escape);
text = p;
}
}