summarylogtreecommitdiffstats
path: root/unread_news.patch
blob: 85c6a695e18a13f66b94da7654fa3e5e651aa854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From 5eba7d9b279aea3de4270947d84d619a34093fe4 Mon Sep 17 00:00:00 2001
From: Olivier Brunel <jjk@jjacky.com>
Date: Mon, 13 Nov 2017 18:18:00 +0100
Subject: [PATCH] news: Fix issue if title needs trimming..

..that is, if a news title (used to determine whether it has been read
or not) could be trimmedg, there was an issue because titles read from
news.conf are trimmed, so the two wouldn't match, and the news
incorrectly considered unread.

To fix this we trim the titles read from the XML (RSS feed) as well.

Thanks to Ada Joule; Also adam777 for the report.

Fixes #57
---
 src/kalu/news.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/kalu/news.c b/src/kalu/news.c
index 49d4058..85deecf 100644
--- a/src/kalu/news.c
+++ b/src/kalu/news.c
@@ -24,6 +24,7 @@
 
 /* C */
 #include <string.h>
+#include <ctype.h>
 
 #ifndef DISABLE_GUI
 /* gtk */
@@ -121,25 +122,45 @@ xml_parser_updates_text (GMarkupParseContext   *context,
 
     if (streq ("title", list->data))
     {
+        gchar *s = (gchar *) text;
+
+        /* if it needs trimming, let's do it. (If not we use text as-is to avoid
+         * a possibly unneeded call strdup) */
+        if (isspace (*s) || isspace (s[strlen (s) - 1]))
+        {
+            s = strtrim (strdup (s));
+        }
+
         /* is this the last item from last check? */
-        if (NULL != config->news_last && streq (config->news_last, text))
+        if (NULL != config->news_last && streq (config->news_last, s))
         {
             parse_updates_data->is_last_reached = TRUE;
+            if (s != text)
+            {
+                free (s);
+            }
             return;
         }
 
         /* was this item already read? */
         FOR_LIST (i, config->news_read)
         {
-            if (streq (i->data, text))
+            if (streq (i->data, s))
             {
+                if (s != text)
+                {
+                    free (s);
+                }
                 return;
             }
         }
 
         /* add title to the new news */
-        parse_updates_data->titles = alpm_list_add (parse_updates_data->titles,
-                strdup (text));
+        if (s == text)
+        {
+            s = strdup (s);
+        }
+        parse_updates_data->titles = alpm_list_add (parse_updates_data->titles, s);
     }
 }
 
@@ -698,12 +719,12 @@ xml_parser_news_text (GMarkupParseContext *context,
         {
             /* make a copy of the title, and store it in list of all titles */
             /* it will not be free-d here. this is done on window_destroy_cb */
-            s = strdup (text);
+            s = strtrim (strdup (text));
             lists = parse_news_data->lists;
             lists[LIST_TITLES_ALL] = alpm_list_add (lists[LIST_TITLES_ALL], s);
 
             /* is this the last item from last check? */
-            if (NULL != config->news_last && streq (config->news_last, text))
+            if (NULL != config->news_last && streq (config->news_last, s))
             {
                 parse_news_data->is_last_reached = TRUE;
                 return;
@@ -712,7 +733,7 @@ xml_parser_news_text (GMarkupParseContext *context,
             /* was this item already read? */
             FOR_LIST (i, config->news_read)
             {
-                if (streq (i->data, text))
+                if (streq (i->data, s))
                 {
                     /* make a note to skip its description as well */
                     skip_next_description = TRUE;