Skip to content

Commit 4f5a09c

Browse files
committed
Merge Sherlock's branch 'Bug 799662' into stable.
2 parents c25373c + bddc64c commit 4f5a09c

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

gnucash/import-export/bi-import/dialog-bi-import.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <glib.h>
3737
#include <glib/gstdio.h>
3838

39+
#include "gnc-glib-utils.h"
3940
#include "gnc-date.h"
4041
#include "gnc-ui.h"
4142
#include "gnc-ui-util.h"
@@ -170,8 +171,15 @@ gnc_bi_import_read_file (const gchar * filename, const gchar * parser_regexp,
170171
if ((l > 0) && (line[l - 1] == '\n'))
171172
line[l - 1] = 0;
172173

173-
// convert line from locale into utf8
174-
line_utf8 = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
174+
// if the line doesn't conform to UTF-8, try a default charcter set
175+
// conversion based on locale
176+
if (g_utf8_validate(line, -1, NULL))
177+
line_utf8 = line;
178+
else
179+
line_utf8 = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
180+
181+
// Remove the potential XML-prohibited codepoints from the UTF-8 compliant string
182+
gnc_utf8_strip_invalid(line_utf8);
175183

176184
// parse the line
177185
match_info = NULL; // it seems, that in contrast to documentation, match_info is not always set -> g_match_info_free will segfault
@@ -216,9 +224,8 @@ gnc_bi_import_read_file (const gchar * filename, const gchar * parser_regexp,
216224
}
217225

218226
g_match_info_free (match_info);
219-
match_info = 0;
220-
g_free (line_utf8);
221-
line_utf8 = 0;
227+
if (line_utf8 != line)
228+
g_free (line_utf8);
222229
}
223230
g_free (line);
224231
line = 0;

gnucash/import-export/csv-imp/csv-account-import.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <glib/gi18n.h>
3131
#include <glib/gstdio.h>
3232

33+
#include "gnc-glib-utils.h"
3334
#include "gnc-ui-util.h"
3435
#include <regex.h>
3536
#include "Account.h"
@@ -98,8 +99,21 @@ csv_import_read_file (GtkWindow *window, const gchar *filename,
9899
return RESULT_OPEN_FAILED;
99100
}
100101

101-
contents = g_locale_to_utf8 (locale_cont, -1, NULL, NULL, NULL);
102-
g_free (locale_cont);
102+
// if the contents don't conform to UTF-8, try a default charcter set
103+
// conversion based on locale
104+
if (g_utf8_validate(locale_cont, -1, NULL))
105+
{
106+
contents = locale_cont;
107+
}
108+
else
109+
{
110+
contents = g_locale_to_utf8 (locale_cont, -1, NULL, NULL, NULL);
111+
g_free (locale_cont);
112+
}
113+
114+
// Remove the potential XML-prohibited codepoints from the UTF-8 compliant content
115+
gnc_utf8_strip_invalid(contents);
116+
103117

104118
// compile the regular expression and check for errors
105119
err = NULL;

gnucash/import-export/customer-import/dialog-customer-import.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <glib.h>
3535
#include <glib/gstdio.h>
3636

37+
#include "gnc-glib-utils.h"
3738
#include "gnc-ui.h"
3839
#include "gnc-ui-util.h"
3940
#include "gnc-gui-query.h"
@@ -135,8 +136,15 @@ gnc_customer_import_read_file (const gchar *filename, const gchar *parser_regexp
135136
if ((l > 0) && (line[l - 1] == '\n'))
136137
line[l - 1] = 0;
137138

138-
// convert line from locale into utf8
139-
line_utf8 = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
139+
// if the line doesn't conform to UTF-8, try a default charcter set
140+
// conversion based on locale
141+
if (g_utf8_validate(line, -1, NULL))
142+
line_utf8 = line;
143+
else
144+
line_utf8 = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
145+
146+
// Remove the potential XML-prohibited codepoints from the UTF-8 compliant string
147+
gnc_utf8_strip_invalid(line_utf8);
140148

141149
// parse the line
142150
match_info = NULL; // it seems, that in contrast to documentation, match_info is not always set -> g_match_info_free will segfault
@@ -176,9 +184,8 @@ gnc_customer_import_read_file (const gchar *filename, const gchar *parser_regexp
176184
}
177185

178186
g_match_info_free (match_info);
179-
match_info = 0;
180-
g_free (line_utf8);
181-
line_utf8 = 0;
187+
if (line_utf8 != line)
188+
g_free (line_utf8);
182189
}
183190
g_free (line);
184191
line = 0;

0 commit comments

Comments
 (0)