summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-06-18 13:51:20 +0200
committerWojtek Kosior <koszko@koszko.org>2022-06-18 13:51:20 +0200
commit1f9ccef9b99a1adfa53cf1a22543f4bdbe2ac068 (patch)
tree2dcaaed5343b4aa8bb83eeaa447b7f958a40c933
parentf33dbdee39953f145bb986a7488e65e55e25d49d (diff)
downloadbrowser-extension-1f9ccef9b99a1adfa53cf1a22543f4bdbe2ac068.tar.gz
browser-extension-1f9ccef9b99a1adfa53cf1a22543f4bdbe2ac068.zip
restore compatibility with IceCat 60
This commit also fixes the --driver option to configure script.
-rw-r--r--common/entities.js31
-rw-r--r--common/jsonschema.js7
-rw-r--r--html/install.js6
-rwxr-xr-xtest/haketilo_test/profiles.py12
4 files changed, 36 insertions, 20 deletions
diff --git a/common/entities.js b/common/entities.js
index 41d6e3b..c24999e 100644
--- a/common/entities.js
+++ b/common/entities.js
@@ -117,24 +117,37 @@ function* get_used_files(item)
#EXPORT get_used_files AS get_files
/*
- * Regex to parse URIs like:
+ * Function to parse URIs like:
* https://hydrilla.koszko.org/schemas/api_mapping_description-2.schema.json
*/
-const name_base_re = "(?<name_base>[^/]*)";
-const major_number_re = "(?<major>[1-9][0-9]*)";
+const name_base_re = "([^/]*)";
+const major_number_re = "([1-9][0-9]*)";
const minor_number_re = "(?:[1-9][0-9]*|0)";
const numbers_rest_re = `(?:\\.${minor_number_re})*`;
-const version_re = `(?<ver>${major_number_re}${numbers_rest_re})`;
+const version_re = `(${major_number_re}${numbers_rest_re})`;
const schema_name_re = `${name_base_re}-${version_re}\\.schema\\.json`;
-const haketilo_schema_name_regex = new RegExp(schema_name_re);
-#EXPORT haketilo_schema_name_regex
+const schema_name_regex = new RegExp(schema_name_re);
+
+const schema_name_parts = ["full", "name_base", "version", "major"];
+
+function parse_schema_uri(uri) {
+ const match = schema_name_regex.exec(uri);
+ if (!match)
+ return match;
+
+ const result = {};
+
+ for (let i = 0; i < schema_name_parts.length; i++)
+ result[schema_name_parts[i]] = match[i];
+
+ return result
+}
+#EXPORT parse_schema_uri
/* Extract the number that indicates entity's compatibility mode. */
function get_schema_major_version(instance) {
- const match = haketilo_schema_name_regex.exec(instance.$schema);
-
- return parseInt(match.groups.major);
+ return parseInt(parse_schema_uri(instance.$schema).major);
}
#EXPORT get_schema_major_version
diff --git a/common/jsonschema.js b/common/jsonschema.js
index 9c4a70c..3a82702 100644
--- a/common/jsonschema.js
+++ b/common/jsonschema.js
@@ -57,7 +57,7 @@
#FROM common/jsonschema/scan.js IMPORT SchemaScanResult, scan
-#FROM common/entities.js IMPORT haketilo_schema_name_regex
+#FROM common/entities.js IMPORT parse_schema_uri
#EXPORT scan
#EXPORT SchemaScanResult
@@ -89,9 +89,8 @@ const haketilo_schemas = [
].reduce((ac, s) => Object.assign(ac, {[s.$id]: s}), {});
for (const [$id, schema] of [...Object.entries(haketilo_schemas)]) {
- const match = haketilo_schema_name_regex.exec($id);
- const schema_name =
- `${match.groups.name_base}-${match.groups.major}.schema.json`;
+ const parsed = parse_schema_uri($id);
+ const schema_name = `${parsed.name_base}-${parsed.major}.schema.json`;
haketilo_schemas[schema_name] = schema;
}
diff --git a/html/install.js b/html/install.js
index 82df661..ce97877 100644
--- a/html/install.js
+++ b/html/install.js
@@ -50,7 +50,7 @@
#FROM common/entities.js IMPORT item_id_string, version_string, get_files
#FROM common/misc.js IMPORT sha256_async AS compute_sha256
#FROM common/jsonschema.js IMPORT haketilo_validator, haketilo_schemas
-#FROM common/entities.js IMPORT haketilo_schema_name_regex
+#FROM common/entities.js IMPORT parse_schema_uri
#FROM html/repo_query_cacher_client.js IMPORT indirect_fetch
@@ -208,8 +208,8 @@ function InstallView(tab_id, on_view_show, on_view_hide) {
`${captype} ${item_id_string(id, ver)} was served using a nonconforming response format.`;
try {
- const match = haketilo_schema_name_regex.exec(json.$schema);
- var major_schema_version = match.groups.major;
+ const parsed = parse_schema_uri(json.$schema);
+ var major_schema_version = parsed.major;
if (!["1", "2"].includes(major_schema_version)) {
const msg = `${captype} ${item_id_string(id, ver)} was served using unsupported Hydrilla API version. You might need to update Haketilo.`;
diff --git a/test/haketilo_test/profiles.py b/test/haketilo_test/profiles.py
index e1fc368..0487064 100755
--- a/test/haketilo_test/profiles.py
+++ b/test/haketilo_test/profiles.py
@@ -81,7 +81,8 @@ def set_webextension_uuid(profile, extension_id, uuid=default_extension_uuid):
json.dumps({extension_id: uuid}))
def firefox_safe_mode(proxy_port, proxy_host=default_proxy_host,
- firefox_binary=conf_settings['BROWSER_BINARY']):
+ firefox_binary=conf_settings['BROWSER_BINARY'],
+ geckodriver_binary=conf_settings['DRIVER']):
"""
Initialize a Firefox instance controlled by selenium. The instance is
started in safe mode.
@@ -94,11 +95,13 @@ def firefox_safe_mode(proxy_port, proxy_host=default_proxy_host,
options.add_argument('--safe-mode')
return HaketiloFirefox(options=options, firefox_profile=profile,
- firefox_binary=firefox_binary)
+ firefox_binary=firefox_binary,
+ executable_path=geckodriver_binary)
def firefox_with_profile(proxy_port, proxy_host=default_proxy_host,
firefox_binary=conf_settings['BROWSER_BINARY'],
- profile_dir=conf_settings['CLEAN_PROFILE']):
+ profile_dir=conf_settings['CLEAN_PROFILE'],
+ geckodriver_binary=conf_settings['DRIVER']):
"""
Initialize a Firefox instance controlled by selenium. The instance is
started using an empty profile (either the default one or the one passed to
@@ -111,4 +114,5 @@ def firefox_with_profile(proxy_port, proxy_host=default_proxy_host,
set_webextension_uuid(profile, default_haketilo_id)
return HaketiloFirefox(firefox_profile=profile,
- firefox_binary=firefox_binary)
+ firefox_binary=firefox_binary,
+ executable_path=geckodriver_binary)