From 8c9ec9a22944e4d47b707d01f084e31ce4512f8a Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Mon, 27 Sep 2021 00:07:03 +0300 Subject: Take html special chars into account when printing blobs. Not a perfect solution --- git_part.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'git_part.c') diff --git a/git_part.c b/git_part.c index fb6d18d..beaf5d0 100644 --- a/git_part.c +++ b/git_part.c @@ -95,7 +95,7 @@ void print_commits(int dir_fd,const git_reference *branch, git_repository *repo) print_commit(current_commit,NULL,log_file,diff_directory_fd,repo); git_revwalk_free(walker); - fclose(log_file); + close_file(log_file); } void print_commit(git_commit *current_commit,git_commit *parent_commit,FILE *log_file,int diff_directory_fd,git_repository *repo) { @@ -200,10 +200,22 @@ int print_entry(FILE *index_file,const git_tree_entry *entry,int base_dir_fd,git push_html_link_for_blob(index_file,entry_name,entry_oid); { FILE *blob_file; - const void *blob_data; + const unsigned char *blob_data; size_t blob_size; + size_t i; git_blob *blob; + static const char *special_chars[256] + = + { + ['\"']=""", + ['\'']="'", + ['&']="&", + ['<']="<", + ['>']=">", + + }; + blob=(git_blob*)obj; blob_file=create_file(base_dir_fd,entry_oid); @@ -211,9 +223,20 @@ int print_entry(FILE *index_file,const git_tree_entry *entry,int base_dir_fd,git blob_size=git_blob_rawsize(blob); blob_data=git_blob_rawcontent(blob); - fwrite(blob_data,blob_size,1,blob_file); - - fclose(blob_file); + fprintf(blob_file,"
\n");
+				for(i=0;i\n");
+
+				close_file(blob_file);
 			}
 			break;
 	}
-- 
cgit v1.2.3