[gjs: 2/3] Gio override: check for missing or conflicting schema path



commit 0ed3038e4d7fb721e0173b79c4315cb9ec348db2
Author: Andy Holmes <andrew g r holmes gmail com>
Date:   Mon Dec 2 21:00:17 2019 -0800

    Gio override: check for missing or conflicting schema path

 installed-tests/js/testGio.js | 12 ++++++++++++
 modules/overrides/Gio.js      | 18 +++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/installed-tests/js/testGio.js b/installed-tests/js/testGio.js
index 677883b2..11ff46dc 100644
--- a/installed-tests/js/testGio.js
+++ b/installed-tests/js/testGio.js
@@ -38,6 +38,18 @@ describe('Gio.Settings overrides', function () {
             .toThrowError(/schema/);
     });
 
+    it("doesn't crash when forgetting to specify a schema path", function () {
+        expect(() => new Gio.Settings({schema: 'org.gnome.GjsTest.Sub'}))
+            .toThrowError(/schema/);
+    });
+
+    it("doesn't crash when specifying conflicting schema paths", function () {
+        expect(() => new Gio.Settings({
+            schema: 'org.gnome.GjsTest',
+            path: '/conflicting/path/',
+        })).toThrowError(/schema/);
+    });
+
     describe('with existing schema', function () {
         const KINDS = ['boolean', 'double', 'enum', 'flags', 'int', 'int64',
             'string', 'strv', 'uint', 'uint64', 'value'];
diff --git a/modules/overrides/Gio.js b/modules/overrides/Gio.js
index caf46ab6..0aa9f437 100644
--- a/modules/overrides/Gio.js
+++ b/modules/overrides/Gio.js
@@ -544,9 +544,25 @@ function _init() {
             }
 
             const source = Gio.SettingsSchemaSource.get_default();
-            if (schemaIdProp && !source.lookup(props[schemaIdProp], true))
+            const settingsSchema = settingsSchemaProp
+                ? props[settingsSchemaProp]
+                : source.lookup(props[schemaIdProp], true);
+
+            if (!settingsSchema)
                 throw new Error(`GSettings schema ${props[schemaIdProp]} not found`);
 
+            const settingsSchemaPath = settingsSchema.get_path();
+            if (props['path'] === undefined && !settingsSchemaPath) {
+                throw new Error('Attempting to create schema ' +
+                    `'${settingsSchema.get_id()}' without a path`);
+            }
+
+            if (props['path'] !== undefined && settingsSchemaPath &&
+                props['path'] !== settingsSchemaPath) {
+                throw new Error(`GSettings created for path '${props['path']}'` +
+                    `, but schema specifies '${settingsSchemaPath}'`);
+            }
+
             return this._realInit(props);
         },
 


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