diff options
author | Gehad elrobey <gehadelrobey@gmail.com> | 2014-06-02 20:10:54 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-06 10:08:09 -0700 |
commit | 464a611d8d5dbef8c3d62320f7b89e6c4ffaab53 (patch) | |
tree | b4c5e4a1221a9a3576215677ce762d5daf1bea7c /membuffer.c | |
parent | 1120379b2bcdc2d941bb2e036bacf34d226e74a1 (diff) | |
download | subsurface-464a611d8d5dbef8c3d62320f7b89e6c4ffaab53.tar.gz |
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>
Diffstat (limited to 'membuffer.c')
-rw-r--r-- | membuffer.c | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/membuffer.c b/membuffer.c index 82816ece6..c8a06662f 100644 --- a/membuffer.c +++ b/membuffer.c @@ -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 = "<"; + break; + case '>': + escape = ">"; + break; + case '&': + escape = "&"; + break; + case '\'': + if (!is_attribute) + continue; + escape = "'"; + break; + case '\"': + if (!is_attribute) + continue; + escape = """; + 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; + } } |