- cut summary on 252 characters and append "..."
- closes rhbz#867118
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/plugins/rhbz.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
index 43a0fcc..c352591 100644
--- a/src/plugins/rhbz.c
+++ b/src/plugins/rhbz.c
@@ -34,6 +34,7 @@
#include <btparser/strbuf.h>
#define MAX_HOPS 5
+#define MAX_SUMMARY_LENGTH 255
//#define DEBUG
@@ -656,6 +657,45 @@ int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t
*problem_data,
strbuf_append_strf(buf_summary, ": TAINTED %s", tainted_short);
}
+ /* If autogenerated summary is longer than max allowed summary length then
+ * try to find first ' ' from the end of acceptable long summary string
+ *
+ * If ' ' is found replace string after that by "..."
+ *
+ * If ' ' is NOT found in maximal allowed range, cut summary string on
+ * lenght (MAX_SUMMARY_LENGTH - strlen("...")) and append "..."
+ *
+ * If MAX_SUMMARY_LENGTH is 15 and max allowed cut is 5:
+ *
+ * 0123456789ABCDEF -> 0123456789AB...
+ * 0123456789 BCDEF -> 0123456789 ...
+ * 012345 789ABCDEF -> 012345 789AB...
+ */
+ if (strlen(buf_summary->buf) > MAX_SUMMARY_LENGTH)
+ {
+ char *max_end = buf_summary->buf + (MAX_SUMMARY_LENGTH -
strlen("..."));
+
+ /* maximal number of characters to cut due to attempt cut summary
+ * string after last ' '
+ */
+ int max_cut = 16;
+
+ /* start looking for ' ' one char before the last possible character */
+ char *buf = max_end - 1;
+ while (buf[0] != ' ' && max_cut--)
+ --buf;
+
+ if (buf[0] != ' ')
+ buf = max_end;
+ else
+ ++buf;
+
+ buf[0] = '.';
+ buf[1] = '.';
+ buf[2] = '.';
+ buf[3] = '\0';
+ }
+
/* Generating of a description according to the RH bugzilla default format:
*
https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora
*/
--
1.7.11.7