From 1f9ccef9b99a1adfa53cf1a22543f4bdbe2ac068 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Sat, 18 Jun 2022 13:51:20 +0200 Subject: restore compatibility with IceCat 60 This commit also fixes the --driver option to configure script. --- common/entities.js | 31 ++++++++++++++++++++++--------- common/jsonschema.js | 7 +++---- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'common') 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 = "(?[^/]*)"; -const major_number_re = "(?[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 = `(?${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; } -- cgit v1.2.3