X-Git-Url: https://git.armaanb.net/?p=stagit.git;a=blobdiff_plain;f=src%2Fstagit.c;h=6b45b3601b9f86b36f18aa3655992f02103b6e28;hp=00409e67f06423cf5d6ebb1eed824bfa8b24e80d;hb=1426ca963932ab7521eb40914f98ff0cc9e00ffb;hpb=e4f82ab1904209a27bc9c4f5fa065287bb576f29 diff --git a/src/stagit.c b/src/stagit.c index 00409e6..6b45b36 100644 --- a/src/stagit.c +++ b/src/stagit.c @@ -280,6 +280,26 @@ xmlencode(FILE *fp, const char *s, size_t len) } } +/* Escape characters below as HTML 2.0 / XML 1.0, ignore printing '\n', '\r' */ +void +xmlencodeline(FILE *fp, const char *s, size_t len) +{ + size_t i; + + for (i = 0; *s && i < len; s++, i++) { + switch(*s) { + case '<': fputs("<", fp); break; + case '>': fputs(">", fp); break; + case '\'': fputs("'", fp); break; + case '&': fputs("&", fp); break; + case '"': fputs(""", fp); break; + case '\r': break; /* ignore CR */ + case '\n': break; /* ignore LF */ + default: putc(*s, fp); + } + } +} + int mkdirp(const char *path) { @@ -617,8 +637,9 @@ printshowfile(FILE *fp, struct commitinfo *ci) fprintf(fp, "-", i, j, k, i, j, k); else - fputc(' ', fp); - xmlencode(fp, line->content, line->content_len); + putc(' ', fp); + xmlencodeline(fp, line->content, line->content_len); + putc('\n', fp); if (line->old_lineno == -1 || line->new_lineno == -1) fputs("", fp); }