AmendHub

Download:

jcs

/

subtext

/

amendments

/

199

board+folder+mail: Trim trailing whitespace from fields


jcs made amendment 199 about 1 year ago
--- board.c Tue Jul 12 10:42:10 2022 +++ board.c Tue Jul 12 22:47:31 2022 @@ -196,7 +196,10 @@ handle_opt: show_list = true; break; case 'p': - board_compose(s, board, NULL, NULL, NULL, NULL); + if (board_compose(s, board, NULL, NULL, NULL, NULL)) { + find_post_ids = true; + show_list = true; + } break; case '>': case '<': @@ -414,8 +417,12 @@ post_compose_start: thread->subject = tmp; session_output(s, "\r\n", 2); session_flush(s); + if (thread->subject == NULL) goto post_compose_done; + + rtrim(thread->subject, "\r\n\t "); + if (thread->subject[0] == '\0') { session_output_template(s, "{{B}}Error:{{/B}} Subject " "cannot be blank (^C to cancel)\r\n"); @@ -440,8 +447,12 @@ post_compose_start: post.body = tmp; session_output(s, "\r\n", 2); session_flush(s); + if (post.body == NULL) goto post_compose_done; + + rtrim(post.body, "\r\n\t "); + if (post.body[0] == '\0') { free(post.body); goto post_compose_done; @@ -621,9 +632,8 @@ board_post_read(struct session *s, struct board *board } break; case 'r': - new_id = board_compose(s, board, &thread, &post, NULL, NULL); - if (new_id) { - ; //ret = POST_READ_RETURN_FIND; + if (board_compose(s, board, &thread, &post, NULL, NULL)) { + ret = POST_READ_RETURN_FIND; done = true; } break; --- folder.c Tue Jul 12 11:32:19 2022 +++ folder.c Tue Jul 12 22:49:24 2022 @@ -503,13 +503,9 @@ file_upload_annotate: free(tmp); session_output(s, "\r\n", 2); session_flush(s); - if (file.filename[0] == '\0') { - session_output_template(s, "{{B}}Error:{{/B}} Filename " - "cannot be blank (^C to cancel)\r\n"); - session_flush(s); - continue; - } + rtrim(file.filename, "\r\n\t "); + if (!folder_file_valid_filename(s, folder, &file, &errorstr)) { session_printf(s, "{{B}}Error:{{/B}} %s\r\n", errorstr); free(errorstr); @@ -531,6 +527,9 @@ file_upload_annotate: free(tmp); session_output(s, "\r\n", 2); session_flush(s); + + rtrim(file.description, "\r\n\t "); + if (file.description[0] == '\0') { session_output_template(s, "{{B}}Error:{{/B}} File " "description cannot be blank (^C to cancel)\r\n"); @@ -556,6 +555,9 @@ file_upload_annotate: file.notes_size = 0; break; } + + rtrim(file.notes, "\r\n\t "); + if (file.notes[0] == '\0') { free(file.notes); file.notes = NULL; --- mail.c Tue Jul 12 09:46:00 2022 +++ mail.c Tue Jul 12 22:45:01 2022 @@ -298,8 +298,12 @@ mail_compose_start: msg.subject = tmp; session_output(s, "\r\n", 2); session_flush(s); + if (msg.subject == NULL) goto mail_compose_done; + + rtrim(msg.subject, "\r\n\t "); + if (msg.subject[0] == '\0') { session_output_template(s, "{{B}}Error:{{/B}} Subject cannot " "be blank (^C to cancel)\r\n"); @@ -324,8 +328,12 @@ mail_compose_start: msg.body = tmp; session_output(s, "\r\n", 2); session_flush(s); + if (msg.body == NULL) goto mail_compose_done; + + rtrim(msg.body, "\r\n\t "); + if (msg.body[0] == '\0') { session_output_template(s, "{{B}}Error:{{/B}} Message cannot " "be blank (^C to cancel)\r\n"); --- util.c Thu Jul 7 16:17:58 2022 +++ util.c Tue Jul 12 17:10:05 2022 @@ -211,6 +211,30 @@ ordinal(unsigned short n) } } +size_t +rtrim(char *str, char *chars) +{ + size_t len, rlen, n, j; + + rlen = len = strlen(str); + + for (n = len; n > 0; n--) { + for (j = 0; chars[j] != '\0'; j++) { + if (str[n - 1] == chars[j]) { + rlen--; + str[n - 1] = '\0'; + goto next_in_str; + } + } + + break; +next_in_str: + continue; + } + + return rlen; +} + long strpos_quoted(char *str, char c) { --- util.h Thu Jun 30 11:31:00 2022 +++ util.h Tue Jul 12 17:10:27 2022 @@ -98,6 +98,7 @@ short getline(char *str, size_t len, char **ret); size_t strlcpy(char *dst, const char *src, size_t dsize); size_t strlcat(char *dst, const char *src, size_t dsize); const char * ordinal(unsigned short n); +size_t rtrim(char *str, char *chars); long strpos_quoted(char *str, char c); char * OSTypeToString(OSType type);