[network-manager-vpnc] properties: suppress warning on import
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-vpnc] properties: suppress warning on import
- Date: Mon, 2 Jul 2012 18:57:25 +0000 (UTC)
commit 9fb8461cc0164dbdedac0b897d59583396482195
Author: Dan Williams <dcbw redhat com>
Date: Mon Jul 2 13:56:43 2012 -0500
properties: suppress warning on import
Return NULL instead of an empty string for string values. Suppresses
warnings like this:
** (nm-connection-editor:5951): CRITICAL **: nm_setting_vpn_add_data_item:
assertion `strlen (item) > 0' failed
** (nm-connection-editor:5951): CRITICAL **: nm_setting_vpn_add_secret:
assertion `strlen (secret) > 0' failed
Reported by Joel Cron <joel cron gmail com>
properties/nm-vpnc-helper.c | 18 ++++++++++--------
properties/tests/test-import-export.c | 26 ++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 8 deletions(-)
---
diff --git a/properties/nm-vpnc-helper.c b/properties/nm-vpnc-helper.c
index 4fd2376..1ea66f8 100644
--- a/properties/nm-vpnc-helper.c
+++ b/properties/nm-vpnc-helper.c
@@ -96,14 +96,16 @@ get_string_as_utf8 (GKeyFile *keyfile,
char *raw, *buf = NULL;
raw = g_key_file_get_value (keyfile, group_name, key, error);
- if (g_utf8_validate (raw, -1, NULL))
- buf = g_key_file_get_string (keyfile, group_name, key, error);
- else {
- /* Attempt to force to UTF8 using current locale, which is about
- * as good as we can do since the file doesn't say what locale
- * it's in.
- */
- buf = g_locale_to_utf8 (raw, -1, NULL, NULL, error);
+ if (raw && raw[0]) {
+ if (g_utf8_validate (raw, -1, NULL))
+ buf = g_key_file_get_string (keyfile, group_name, key, error);
+ else {
+ /* Attempt to force to UTF8 using current locale, which is about
+ * as good as we can do since the file doesn't say what locale
+ * it's in.
+ */
+ buf = g_locale_to_utf8 (raw, -1, NULL, NULL, error);
+ }
}
g_free (raw);
return buf;
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 628d026..bdd06bd 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -37,6 +37,7 @@
#include "nm-test-helpers.h"
#include "properties/nm-vpnc.h"
#include "src/nm-vpnc-service.h"
+#include "properties/nm-vpnc-helper.h"
typedef struct {
const char *name;
@@ -737,6 +738,29 @@ test_legacy_ike_port_1_import (NMVpnPluginUiInterface *plugin, const char *dir)
g_free (pcf);
}
+static void
+test_empty_keyfile_string_null (const char *dir)
+{
+ char *pcf, *val;
+ GError *error = NULL;
+ GKeyFile *kf;
+ gboolean success;
+
+ pcf = g_build_path ("/", dir, "basic.pcf", NULL);
+ g_assert (pcf);
+
+ kf = g_key_file_new ();
+ success = g_key_file_load_from_file (kf, pcf, 0, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ val = key_file_get_string_helper (kf, "main", "ISPCommand", NULL);
+ g_assert (val == NULL);
+
+ g_free (pcf);
+ g_key_file_free (kf);
+}
+
int main (int argc, char **argv)
{
GError *error = NULL;
@@ -776,6 +800,8 @@ int main (int argc, char **argv)
test_nat_export (plugin, argv[1], argv[2], NM_VPNC_NATT_MODE_NATT);
test_nat_export (plugin, argv[1], argv[2], NM_VPNC_NATT_MODE_NATT_ALWAYS);
+ test_empty_keyfile_string_null (argv[1]);
+
g_object_unref (plugin);
basename = g_path_get_basename (argv[0]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]