Fossil SCM

Do not allow forum posts that are replies or the start of a new message if they contain no content. An edit with no content is ok, as that means the post is to be deleted.

drh 2020-04-17 14:38 trunk
Commit d2c81b9d6aed153cfe9fe53667f7778fc7c4f898614fffeea20719eb9321339e
1 file changed +19 -6
+19 -6
--- src/forum.c
+++ src/forum.c
@@ -753,10 +753,19 @@
753753
if( P("domod") ) return 1;
754754
if( g.perm.WrTForum ) return 0;
755755
if( g.perm.ModForum ) return 0;
756756
return 1;
757757
}
758
+
759
+/*
760
+** Return true if the string is white-space only.
761
+*/
762
+static int whitespace_only(const char *z){
763
+ if( z==0 ) return 1;
764
+ while( z[0] && fossil_isspace(z[0]) ){ z++; }
765
+ return z[0]==0;
766
+}
758767
759768
/*
760769
** Add a new Forum Post artifact to the repository.
761770
**
762771
** Return true if a redirect occurs.
@@ -773,12 +782,16 @@
773782
char *zI;
774783
char *zG;
775784
int iBasis;
776785
Blob x, cksum, formatCheck, errMsg;
777786
Manifest *pPost;
787
+ int nContent = zContent ? (int)strlen(zContent) : 0;
778788
779789
schema_forum();
790
+ if( iEdit==0 && whitespace_only(zContent) ){
791
+ return 0;
792
+ }
780793
if( iInReplyTo==0 && iEdit>0 ){
781794
iBasis = iEdit;
782795
iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit);
783796
}else{
784797
iBasis = iInReplyTo;
@@ -819,11 +832,11 @@
819832
}else{
820833
zUser = login_name();
821834
}
822835
}
823836
blob_appendf(&x, "U %F\n", zUser);
824
- blob_appendf(&x, "W %d\n%s\n", strlen(zContent), zContent);
837
+ blob_appendf(&x, "W %d\n%s\n", nContent, zContent);
825838
md5sum_blob(&x, &cksum);
826839
blob_appendf(&x, "Z %b\n", &cksum);
827840
blob_reset(&cksum);
828841
829842
/* Verify that the artifact we are creating is well-formed */
@@ -953,21 +966,21 @@
953966
return;
954967
}
955968
if( P("submit") && cgi_csrf_safe(1) ){
956969
if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent) ) return;
957970
}
958
- if( P("preview") ){
971
+ if( P("preview") && !whitespace_only(zContent) ){
959972
@ <h1>Preview:</h1>
960973
forum_render(zTitle, zMimetype, zContent, "forumEdit", 1);
961974
}
962975
style_header("New Forum Thread");
963976
@ <form action="%R/forume1" method="POST">
964977
@ <h1>New Thread:</h1>
965978
forum_from_line();
966979
forum_entry_widget(zTitle, zMimetype, zContent);
967980
@ <input type="submit" name="preview" value="Preview">
968
- if( P("preview") ){
981
+ if( P("preview") && !whitespace_only(zContent) ){
969982
@ <input type="submit" name="submit" value="Submit">
970983
}else{
971984
@ <input type="submit" name="submit" value="Submit" disabled>
972985
}
973986
if( g.perm.Debug ){
@@ -1053,11 +1066,11 @@
10531066
}
10541067
return;
10551068
}
10561069
}
10571070
isDelete = P("nullout")!=0;
1058
- if( P("submit") && isCsrfSafe ){
1071
+ if( P("submit") && (isDelete || !whitespace_only(zContent)) && isCsrfSafe ){
10591072
int done = 1;
10601073
const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
10611074
const char *zContent = PDT("content","");
10621075
if( P("reply") ){
10631076
done = forum_post(0, fpid, 0, 0, zMimetype, zContent);
@@ -1124,11 +1137,11 @@
11241137
zDisplayName = display_name_from_login(pPost->zUser);
11251138
@ <h3 class='forumPostHdr'>By %h(zDisplayName) on %h(zDate)</h3>
11261139
fossil_free(zDisplayName);
11271140
fossil_free(zDate);
11281141
forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1);
1129
- if( P("preview") ){
1142
+ if( P("preview") && !whitespace_only(zContent) ){
11301143
@ <h2>Preview:</h2>
11311144
forum_render(0, zMimetype,zContent, "forumEdit", 1);
11321145
}
11331146
@ <h2>Enter Reply:</h2>
11341147
@ <form action="%R/forume2" method="POST">
@@ -1139,11 +1152,11 @@
11391152
}
11401153
if( !isDelete ){
11411154
@ <input type="submit" name="preview" value="Preview">
11421155
}
11431156
@ <input type="submit" name="cancel" value="Cancel">
1144
- if( P("preview") || isDelete ){
1157
+ if( (P("preview") && !whitespace_only(zContent)) || isDelete ){
11451158
@ <input type="submit" name="submit" value="Submit">
11461159
}
11471160
if( g.perm.Debug ){
11481161
/* For the test-forumnew page add these extra debugging controls */
11491162
@ <div class="debug">
11501163
--- src/forum.c
+++ src/forum.c
@@ -753,10 +753,19 @@
753 if( P("domod") ) return 1;
754 if( g.perm.WrTForum ) return 0;
755 if( g.perm.ModForum ) return 0;
756 return 1;
757 }
 
 
 
 
 
 
 
 
 
758
759 /*
760 ** Add a new Forum Post artifact to the repository.
761 **
762 ** Return true if a redirect occurs.
@@ -773,12 +782,16 @@
773 char *zI;
774 char *zG;
775 int iBasis;
776 Blob x, cksum, formatCheck, errMsg;
777 Manifest *pPost;
 
778
779 schema_forum();
 
 
 
780 if( iInReplyTo==0 && iEdit>0 ){
781 iBasis = iEdit;
782 iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit);
783 }else{
784 iBasis = iInReplyTo;
@@ -819,11 +832,11 @@
819 }else{
820 zUser = login_name();
821 }
822 }
823 blob_appendf(&x, "U %F\n", zUser);
824 blob_appendf(&x, "W %d\n%s\n", strlen(zContent), zContent);
825 md5sum_blob(&x, &cksum);
826 blob_appendf(&x, "Z %b\n", &cksum);
827 blob_reset(&cksum);
828
829 /* Verify that the artifact we are creating is well-formed */
@@ -953,21 +966,21 @@
953 return;
954 }
955 if( P("submit") && cgi_csrf_safe(1) ){
956 if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent) ) return;
957 }
958 if( P("preview") ){
959 @ <h1>Preview:</h1>
960 forum_render(zTitle, zMimetype, zContent, "forumEdit", 1);
961 }
962 style_header("New Forum Thread");
963 @ <form action="%R/forume1" method="POST">
964 @ <h1>New Thread:</h1>
965 forum_from_line();
966 forum_entry_widget(zTitle, zMimetype, zContent);
967 @ <input type="submit" name="preview" value="Preview">
968 if( P("preview") ){
969 @ <input type="submit" name="submit" value="Submit">
970 }else{
971 @ <input type="submit" name="submit" value="Submit" disabled>
972 }
973 if( g.perm.Debug ){
@@ -1053,11 +1066,11 @@
1053 }
1054 return;
1055 }
1056 }
1057 isDelete = P("nullout")!=0;
1058 if( P("submit") && isCsrfSafe ){
1059 int done = 1;
1060 const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
1061 const char *zContent = PDT("content","");
1062 if( P("reply") ){
1063 done = forum_post(0, fpid, 0, 0, zMimetype, zContent);
@@ -1124,11 +1137,11 @@
1124 zDisplayName = display_name_from_login(pPost->zUser);
1125 @ <h3 class='forumPostHdr'>By %h(zDisplayName) on %h(zDate)</h3>
1126 fossil_free(zDisplayName);
1127 fossil_free(zDate);
1128 forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1);
1129 if( P("preview") ){
1130 @ <h2>Preview:</h2>
1131 forum_render(0, zMimetype,zContent, "forumEdit", 1);
1132 }
1133 @ <h2>Enter Reply:</h2>
1134 @ <form action="%R/forume2" method="POST">
@@ -1139,11 +1152,11 @@
1139 }
1140 if( !isDelete ){
1141 @ <input type="submit" name="preview" value="Preview">
1142 }
1143 @ <input type="submit" name="cancel" value="Cancel">
1144 if( P("preview") || isDelete ){
1145 @ <input type="submit" name="submit" value="Submit">
1146 }
1147 if( g.perm.Debug ){
1148 /* For the test-forumnew page add these extra debugging controls */
1149 @ <div class="debug">
1150
--- src/forum.c
+++ src/forum.c
@@ -753,10 +753,19 @@
753 if( P("domod") ) return 1;
754 if( g.perm.WrTForum ) return 0;
755 if( g.perm.ModForum ) return 0;
756 return 1;
757 }
758
759 /*
760 ** Return true if the string is white-space only.
761 */
762 static int whitespace_only(const char *z){
763 if( z==0 ) return 1;
764 while( z[0] && fossil_isspace(z[0]) ){ z++; }
765 return z[0]==0;
766 }
767
768 /*
769 ** Add a new Forum Post artifact to the repository.
770 **
771 ** Return true if a redirect occurs.
@@ -773,12 +782,16 @@
782 char *zI;
783 char *zG;
784 int iBasis;
785 Blob x, cksum, formatCheck, errMsg;
786 Manifest *pPost;
787 int nContent = zContent ? (int)strlen(zContent) : 0;
788
789 schema_forum();
790 if( iEdit==0 && whitespace_only(zContent) ){
791 return 0;
792 }
793 if( iInReplyTo==0 && iEdit>0 ){
794 iBasis = iEdit;
795 iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit);
796 }else{
797 iBasis = iInReplyTo;
@@ -819,11 +832,11 @@
832 }else{
833 zUser = login_name();
834 }
835 }
836 blob_appendf(&x, "U %F\n", zUser);
837 blob_appendf(&x, "W %d\n%s\n", nContent, zContent);
838 md5sum_blob(&x, &cksum);
839 blob_appendf(&x, "Z %b\n", &cksum);
840 blob_reset(&cksum);
841
842 /* Verify that the artifact we are creating is well-formed */
@@ -953,21 +966,21 @@
966 return;
967 }
968 if( P("submit") && cgi_csrf_safe(1) ){
969 if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent) ) return;
970 }
971 if( P("preview") && !whitespace_only(zContent) ){
972 @ <h1>Preview:</h1>
973 forum_render(zTitle, zMimetype, zContent, "forumEdit", 1);
974 }
975 style_header("New Forum Thread");
976 @ <form action="%R/forume1" method="POST">
977 @ <h1>New Thread:</h1>
978 forum_from_line();
979 forum_entry_widget(zTitle, zMimetype, zContent);
980 @ <input type="submit" name="preview" value="Preview">
981 if( P("preview") && !whitespace_only(zContent) ){
982 @ <input type="submit" name="submit" value="Submit">
983 }else{
984 @ <input type="submit" name="submit" value="Submit" disabled>
985 }
986 if( g.perm.Debug ){
@@ -1053,11 +1066,11 @@
1066 }
1067 return;
1068 }
1069 }
1070 isDelete = P("nullout")!=0;
1071 if( P("submit") && (isDelete || !whitespace_only(zContent)) && isCsrfSafe ){
1072 int done = 1;
1073 const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE);
1074 const char *zContent = PDT("content","");
1075 if( P("reply") ){
1076 done = forum_post(0, fpid, 0, 0, zMimetype, zContent);
@@ -1124,11 +1137,11 @@
1137 zDisplayName = display_name_from_login(pPost->zUser);
1138 @ <h3 class='forumPostHdr'>By %h(zDisplayName) on %h(zDate)</h3>
1139 fossil_free(zDisplayName);
1140 fossil_free(zDate);
1141 forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1);
1142 if( P("preview") && !whitespace_only(zContent) ){
1143 @ <h2>Preview:</h2>
1144 forum_render(0, zMimetype,zContent, "forumEdit", 1);
1145 }
1146 @ <h2>Enter Reply:</h2>
1147 @ <form action="%R/forume2" method="POST">
@@ -1139,11 +1152,11 @@
1152 }
1153 if( !isDelete ){
1154 @ <input type="submit" name="preview" value="Preview">
1155 }
1156 @ <input type="submit" name="cancel" value="Cancel">
1157 if( (P("preview") && !whitespace_only(zContent)) || isDelete ){
1158 @ <input type="submit" name="submit" value="Submit">
1159 }
1160 if( g.perm.Debug ){
1161 /* For the test-forumnew page add these extra debugging controls */
1162 @ <div class="debug">
1163

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button