aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiltjo Posthuma <[email protected]>2021-03-25 18:13:13 +0100
committerHiltjo Posthuma <[email protected]>2021-03-25 18:13:13 +0100
commit295e4b8cb95114bb74b582c7332bc4c171f36dd3 (patch)
treedb5aa2e65b47071855703031dcc1b5ade83c75a9
parent995f7d5c5d8e396b06e70b1497ac96df63ffec36 (diff)
downloadstagit-295e4b8cb95114bb74b582c7332bc4c171f36dd3.tar.gz
stagit-295e4b8cb95114bb74b582c7332bc4c171f36dd3.zip
add function to print a single line, ignoring \r and \n
This can happen when there is no newline at end of file in the diff which is served by libgit2 as: "\n\ No newline at end of file\n".
-rw-r--r--stagit.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/stagit.c b/stagit.c
index 5043c0d..94c6b83 100644
--- a/stagit.c
+++ b/stagit.c
@@ -377,6 +377,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("&lt;", fp); break;
+ case '>': fputs("&gt;", fp); break;
+ case '\'': fputs("&#39;", fp); break;
+ case '&': fputs("&amp;", fp); break;
+ case '"': fputs("&quot;", fp); break;
+ case '\r': break; /* ignore CR */
+ case '\n': break; /* ignore LF */
+ default: putc(*s, fp);
+ }
+ }
+}
+
int
mkdirp(const char *path)
{
@@ -678,7 +698,8 @@ printshowfile(FILE *fp, struct commitinfo *ci)
i, j, k, i, j, k);
else
putc(' ', fp);
- xmlencode(fp, line->content, line->content_len);
+ xmlencodeline(fp, line->content, line->content_len);
+ putc('\n', fp);
if (line->old_lineno == -1 || line->new_lineno == -1)
fputs("</a>", fp);
}