From 9ca7c88d7c56b4bdbf2380ffeb663d700404ea35 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 11 May 2016 18:13:26 -0400 Subject: Modifications to butcomment so it can accept newlines --- cgi-bin/a.exe | Bin 70440 -> 69591 bytes ws2a/bugcomment.c | 8 ++++++++ ws2a/testhtmlreplace.c | 37 +++++++++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/cgi-bin/a.exe b/cgi-bin/a.exe index ce182f6..df6b2d0 100644 Binary files a/cgi-bin/a.exe and b/cgi-bin/a.exe differ diff --git a/ws2a/bugcomment.c b/ws2a/bugcomment.c index eeba8fe..6464314 100644 --- a/ws2a/bugcomment.c +++ b/ws2a/bugcomment.c @@ -24,6 +24,14 @@ char* replaceHTML(char* str){ int hex; sscanf(str+strp,"%%%x",&hex); //printf("Was:%c\n",(char)hex); + if(hex == 0x0D) continue; + if(hex == 0x0A){ + nstr[nstrp] = '\\'; + nstr[nstrp+1] = 'n'; + nstrp+=2; + strp++; + continue; + } nstr[nstrp] = (char)hex; nstrp++; strp+=3; diff --git a/ws2a/testhtmlreplace.c b/ws2a/testhtmlreplace.c index 56bd5cd..6ac6f90 100644 --- a/ws2a/testhtmlreplace.c +++ b/ws2a/testhtmlreplace.c @@ -3,29 +3,43 @@ #include #include -void replaceHTML(char* str){ - printf("Replaceing:%s\n",str); +char* replaceHTML(char* str){ + //printf("Replaceing:%s\n",str); char* nstr = malloc((sizeof(char)*strlen(str)) + 1); if(nstr == NULL){ + printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); printf("Failed to allocate memory!\n"); } int strp = 0; int nstrp = 0; while(str[strp] != '\0'){ - printf("Strp=%d nstrp=%d\n",strp,nstrp); + //printf("Strp=%d nstrp=%d\n",strp,nstrp); if(str[strp] == '+'){ nstr[nstrp] = ' '; strp++; nstrp++; }else if(str[strp] == '%'){ - printf("Hit encodeing!\n"); + //printf("Hit encodeing!\n"); int hex; sscanf(str+strp,"%%%x",&hex); - printf("Was:%c\n",(char)hex); + //printf("Was:%c\n",(char)hex); + if(hex == 0x0D) continue; + if(hex == 0x0A){ + nstr[nstrp] = '\\'; + nstr[nstrp+1] = 'n'; + nstrp+=2; + strp++; + continue; + } nstr[nstrp] = (char)hex; nstrp++; strp+=3; + }else if(str[strp] == '\n'){ + nstr[nstrp] = '\\'; + nstr[nstrp+1] = 'n'; + nstrp+=2; + strp++; }else{ nstr[nstrp] = str[strp]; nstrp++; @@ -33,7 +47,8 @@ void replaceHTML(char* str){ } } nstr[nstrp] = '\0'; - printf("Done, str is now:%s\n",nstr); + //printf("Done, str is now:%s\n",nstr); + return nstr; } char* useridhash(char* str){ @@ -67,9 +82,11 @@ char* useridhash(char* str){ } int main(){ - char teststring[] = "This+is+a+test"; - useridhash(teststring); - char teststring2[] = "This+is+a+tost"; - useridhash(teststring2); + char teststring[] = "This+is+a+test\nWith\nSome\nNewlines"; + char* parsed = replaceHTML(teststring); + printf("%s\n",parsed); + char teststring2[] = "This+is+another+test"; + char* parsed2 = replaceHTML(teststring2); + printf("%s\n",parsed2); return 0; } -- cgit v1.2.3-70-g09d2