summaryrefslogtreecommitdiff
path: root/nonprism/grilo-plugins/0002-local-metadata-Fixes-to-video_sanitise_string-non-al.patch
blob: dc7abbb52692bd2e5516aa9b0c8b6a6feadb7800 (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
From a05b159c330a7a65479bba35bc529d0934640627 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <jan.steffens@gmail.com>
Date: Tue, 19 May 2015 20:53:28 +0200
Subject: [PATCH 2/2] local-metadata: Fixes to video_sanitise_string non-alnum
 handling

- Extract loop condition into a helper function
- Use g_utf8_get_char to properly convert to unichar
- Be more defensive about g_utf8_find_prev_char returning NULL

https://bugzilla.gnome.org/show_bug.cgi?id=748604
---
 src/local-metadata/grl-local-metadata.c | 39 +++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/local-metadata/grl-local-metadata.c b/src/local-metadata/grl-local-metadata.c
index 45856be..c7f731e 100644
--- a/src/local-metadata/grl-local-metadata.c
+++ b/src/local-metadata/grl-local-metadata.c
@@ -242,6 +242,28 @@ grl_local_metadata_source_set_property (GObject      *object,
 
 /* ======================= Utilities ==================== */
 
+static gboolean
+is_nonalnum (const gchar *str)
+{
+  gunichar uchar;
+
+  if (str == NULL) {
+    return FALSE;
+  }
+
+  uchar = g_utf8_get_char (str);
+
+  if (g_unichar_isalnum (uchar)) {
+    return FALSE;
+  }
+
+  if (uchar == '!' || uchar == '?' || uchar == '.') {
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
 static gchar *
 video_sanitise_string (const gchar *str)
 {
@@ -270,22 +292,17 @@ video_sanitise_string (const gchar *str)
   }
 
   if (*line_end != '\0') {
-    line_end = g_utf8_find_prev_char (line, line_end);
-
+    /* After removing substring with blacklisted word, ignore non alpha-numeric
+     * char in the end of the sanitised string */
+    do {
+      line_end = g_utf8_find_prev_char (line, line_end);
+    } while (is_nonalnum (line_end));
 
     /* If everything in the string is blacklisted, just ignore
      * the blackisting logic.
      */
-    if (line_end == NULL)
+    if (line_end == NULL) {
       return g_strdup (str);
-
-    /* After removing substring with blacklisted word, ignore non alpha-numeric
-     * char in the end of the sanitised string */
-    while (g_unichar_isalnum (*line_end) == FALSE &&
-           *line_end != '!' &&
-           *line_end != '?' &&
-           *line_end != '.') {
-      line_end = g_utf8_find_prev_char (line, line_end);
     }
 
     return g_strndup (line, line_end - line);
-- 
2.4.0