[epiphany] password-manager: password_field can be NULL too



commit 9cad247d28e4c6d5fef9893a7d25e55745306d2c
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Sun Sep 24 13:43:38 2017 +0300

    password-manager: password_field can be NULL too

 lib/sync/ephy-password-manager.c |    2 +-
 lib/sync/ephy-password-record.c  |   21 +++++++++------------
 2 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index bf8b6f7..6695666 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -535,7 +535,7 @@ secret_service_search_cb (SecretService  *service,
     LOG ("Found password record for (%s, %s, %s, %s, %s)",
          origin, target_origin, username, username_field, password_field);
 
-    if (!id || !origin || !target_origin || !password_field || !timestamp) {
+    if (!id || !origin || !target_origin || !timestamp) {
       LOG ("Password record is corrupted, skipping it...");
       goto next;
     }
diff --git a/lib/sync/ephy-password-record.c b/lib/sync/ephy-password-record.c
index 0df8bbc..7e2d374 100644
--- a/lib/sync/ephy-password-record.c
+++ b/lib/sync/ephy-password-record.c
@@ -361,13 +361,11 @@ serializable_serialize_property (JsonSerializable *serializable,
                                  const GValue     *value,
                                  GParamSpec       *pspec)
 {
-  /* Firefox expects null usernames as empty strings. */
-  if (!g_strcmp0 (name, "username") || !g_strcmp0 (name, "usernameField")) {
-    if (g_value_get_string (value) == NULL) {
-      JsonNode *node = json_node_new (JSON_NODE_VALUE);
-      json_node_set_string (node, "");
-      return node;
-    }
+  /* Convert NULL to "", as Firefox expects empty strings for missing fields. */
+  if (G_VALUE_HOLDS_STRING (value) && g_value_get_string (value) == NULL) {
+    JsonNode *node = json_node_new (JSON_NODE_VALUE);
+    json_node_set_string (node, "");
+    return node;
   }
 
   return json_serializable_default_serialize_property (serializable, name, value, pspec);
@@ -380,11 +378,10 @@ serializable_deserialize_property (JsonSerializable *serializable,
                                    GParamSpec       *pspec,
                                    JsonNode         *node)
 {
-  if (!g_strcmp0 (name, "username") || !g_strcmp0 (name, "usernameField")) {
-    if (!g_strcmp0 (json_node_get_string (node), "")) {
-      g_value_set_string (value, NULL);
-      return TRUE;
-    }
+  /* Convert "" back to NULL. */
+  if (G_VALUE_HOLDS_STRING (value) && !g_strcmp0 (json_node_get_string (node), "")) {
+    g_value_set_string (value, NULL);
+    return TRUE;
   }
 
   return json_serializable_default_deserialize_property (serializable, name, value, pspec, node);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]