Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ECDb and ECObjects more resilient to handle schema evolutions #7152

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

RohitPtnkr1996
Copy link
Contributor

WIP


interface UnknownObject { readonly [name: string]: unknown }
function isObject(x: unknown): x is UnknownObject {
return typeof (x) === "object";
}

const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High

This string, which is used as a regular expression
here
, has an unescaped '.' before 'bentley.com/json_schemas/ec', so it might match more hosts than expected.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to escape the . character in the SCHEMAURL_JSON constant. This will ensure that the regular expression matches the exact domain dev.bentley.com and not any other unintended domains. The change involves modifying the SCHEMAURL_JSON constant to escape the . character properly.

core/ecschema-metadata/src/Deserialization/JsonParser.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Deserialization/JsonParser.ts b/core/ecschema-metadata/src/Deserialization/JsonParser.ts
--- a/core/ecschema-metadata/src/Deserialization/JsonParser.ts
+++ b/core/ecschema-metadata/src/Deserialization/JsonParser.ts
@@ -23,3 +23,3 @@
 
-const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";
+const SCHEMAURL_JSON = "https://dev\\.bentley\\.com/json_schemas/ec";
 
EOF
@@ -23,3 +23,3 @@

const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";
const SCHEMAURL_JSON = "https://dev\\.bentley\\.com/json_schemas/ec";

Copilot is powered by AI and may make mistakes. Always verify output.

interface UnknownObject { readonly [name: string]: unknown }
function isObject(x: unknown): x is UnknownObject {
return typeof (x) === "object";
}

const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to remove the unnecessary escape sequence \. from the string https://dev\.bentley\.com/json_schemas/ec. This will ensure that the string is correctly interpreted and does not contain redundant escape sequences. The change should be made in the file core/ecschema-metadata/src/Deserialization/JsonParser.ts on line 24.

core/ecschema-metadata/src/Deserialization/JsonParser.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Deserialization/JsonParser.ts b/core/ecschema-metadata/src/Deserialization/JsonParser.ts
--- a/core/ecschema-metadata/src/Deserialization/JsonParser.ts
+++ b/core/ecschema-metadata/src/Deserialization/JsonParser.ts
@@ -23,3 +23,3 @@
 
-const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";
+const SCHEMAURL_JSON = "https://dev.bentley.com/json_schemas/ec";
 
EOF
@@ -23,3 +23,3 @@

const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";
const SCHEMAURL_JSON = "https://dev.bentley.com/json_schemas/ec";

Copilot is powered by AI and may make mistakes. Always verify output.

interface UnknownObject { readonly [name: string]: unknown }
function isObject(x: unknown): x is UnknownObject {
return typeof (x) === "object";
}

const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to remove the unnecessary escape sequence in the SCHEMAURL_JSON string. Specifically, we should replace https://dev\.bentley\.com/json_schemas/ec with https://dev.bentley.com/json_schemas/ec. This change ensures that the string is correctly interpreted and used in the regular expression without any unintended consequences.

core/ecschema-metadata/src/Deserialization/JsonParser.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Deserialization/JsonParser.ts b/core/ecschema-metadata/src/Deserialization/JsonParser.ts
--- a/core/ecschema-metadata/src/Deserialization/JsonParser.ts
+++ b/core/ecschema-metadata/src/Deserialization/JsonParser.ts
@@ -23,3 +23,3 @@
 
-const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";
+const SCHEMAURL_JSON = "https://dev.bentley.com/json_schemas/ec";
 
EOF
@@ -23,3 +23,3 @@

const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec";
const SCHEMAURL_JSON = "https://dev.bentley.com/json_schemas/ec";

Copilot is powered by AI and may make mistakes. Always verify output.
@@ -605,8 +669,22 @@
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`);
}

if (SCHEMAURL3_2_JSON !== schemaProps.$schema && SCHEMAURL3_2_XML !== schemaProps.$schema) // TODO: Allow for 3.x URI versions to allow the API to read newer specs. (Start at 3.2 though)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema ${this.name} has an unsupported namespace '${schemaProps.$schema}'.`);
if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to ensure that the backslashes are correctly escaped in the string literal so that they are interpreted as literal backslashes in the regular expression. This can be achieved by doubling the backslashes in the string literal.

  • Change the regular expression string from https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema to https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema.
  • Similarly, change the regular expression string from http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+) to http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+).
core/ecschema-metadata/src/Metadata/Schema.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Metadata/Schema.ts b/core/ecschema-metadata/src/Metadata/Schema.ts
--- a/core/ecschema-metadata/src/Metadata/Schema.ts
+++ b/core/ecschema-metadata/src/Metadata/Schema.ts
@@ -671,3 +671,3 @@
 
-    if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
+    if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
       throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
EOF
@@ -671,3 +671,3 @@

if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -605,8 +669,22 @@
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`);
}

if (SCHEMAURL3_2_JSON !== schemaProps.$schema && SCHEMAURL3_2_XML !== schemaProps.$schema) // TODO: Allow for 3.x URI versions to allow the API to read newer specs. (Start at 3.2 though)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema ${this.name} has an unsupported namespace '${schemaProps.$schema}'.`);
if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to ensure that the backslashes are correctly interpreted in the string literal so that the regular expression matches a literal period character. This can be achieved by doubling the backslashes in the string literal. Specifically, we need to replace \. with \\. in the regular expression strings.

  • Change the regular expression strings on line 672 to use double backslashes.
  • Ensure that the regular expressions correctly match the intended schema URLs.
core/ecschema-metadata/src/Metadata/Schema.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Metadata/Schema.ts b/core/ecschema-metadata/src/Metadata/Schema.ts
--- a/core/ecschema-metadata/src/Metadata/Schema.ts
+++ b/core/ecschema-metadata/src/Metadata/Schema.ts
@@ -671,3 +671,3 @@
 
-    if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
+    if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
       throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
EOF
@@ -671,3 +671,3 @@

if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -605,8 +669,22 @@
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`);
}

if (SCHEMAURL3_2_JSON !== schemaProps.$schema && SCHEMAURL3_2_XML !== schemaProps.$schema) // TODO: Allow for 3.x URI versions to allow the API to read newer specs. (Start at 3.2 though)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema ${this.name} has an unsupported namespace '${schemaProps.$schema}'.`);
if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to ensure that the period character in the regular expression is correctly escaped to match a literal period. In a string literal, this requires using double backslashes (\\.) to ensure the backslash is correctly interpreted in the regular expression.

  • Change the escape sequence \. to \\. in the regular expression strings on line 672.
  • This change ensures that the regular expression matches a literal period character in the URLs.
core/ecschema-metadata/src/Metadata/Schema.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Metadata/Schema.ts b/core/ecschema-metadata/src/Metadata/Schema.ts
--- a/core/ecschema-metadata/src/Metadata/Schema.ts
+++ b/core/ecschema-metadata/src/Metadata/Schema.ts
@@ -671,3 +671,3 @@
 
-    if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
+    if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
       throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
EOF
@@ -671,3 +671,3 @@

if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -605,8 +669,22 @@
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`);
}

if (SCHEMAURL3_2_JSON !== schemaProps.$schema && SCHEMAURL3_2_XML !== schemaProps.$schema) // TODO: Allow for 3.x URI versions to allow the API to read newer specs. (Start at 3.2 though)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema ${this.name} has an unsupported namespace '${schemaProps.$schema}'.`);
if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to ensure that the backslashes are correctly interpreted in the string literal so that the regular expression matches a literal dot character. This can be achieved by doubling the backslashes in the string literal. Specifically, we need to replace \. with \\. in the regular expression strings.

  • Change the regular expression strings on line 672 to use double backslashes for escaping the dot character.
  • No additional methods, imports, or definitions are needed to implement this change.
core/ecschema-metadata/src/Metadata/Schema.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Metadata/Schema.ts b/core/ecschema-metadata/src/Metadata/Schema.ts
--- a/core/ecschema-metadata/src/Metadata/Schema.ts
+++ b/core/ecschema-metadata/src/Metadata/Schema.ts
@@ -671,3 +671,3 @@
 
-    if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
+    if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
       throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
EOF
@@ -671,3 +671,3 @@

if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -605,8 +669,22 @@
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`);
}

if (SCHEMAURL3_2_JSON !== schemaProps.$schema && SCHEMAURL3_2_XML !== schemaProps.$schema) // TODO: Allow for 3.x URI versions to allow the API to read newer specs. (Start at 3.2 though)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema ${this.name} has an unsupported namespace '${schemaProps.$schema}'.`);
if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to remove the unnecessary escape sequences in the regular expression strings. Specifically, we should replace \. with . in the regular expression patterns. This change will not alter the functionality of the code but will make the regular expressions clearer and more correct.

  • Locate the regular expression patterns in the fromJSONSync method.
  • Remove the unnecessary escape sequences from the patterns.
  • Ensure that the regular expressions still function as intended.
core/ecschema-metadata/src/Metadata/Schema.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Metadata/Schema.ts b/core/ecschema-metadata/src/Metadata/Schema.ts
--- a/core/ecschema-metadata/src/Metadata/Schema.ts
+++ b/core/ecschema-metadata/src/Metadata/Schema.ts
@@ -671,3 +671,3 @@
 
-    if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
+    if (schemaProps.$schema.match(`https://dev.bentley.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www.bentley.com/schemas/Bentley.ECXML.([0-9]+)`) == null)
       throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
EOF
@@ -671,3 +671,3 @@

if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
if (schemaProps.$schema.match(`https://dev.bentley.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www.bentley.com/schemas/Bentley.ECXML.([0-9]+)`) == null)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -605,8 +669,22 @@
throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Schema ${this.name} has the version '${this.schemaKey.version}' that does not match the provided version '${schemaProps.version}'.`);
}

if (SCHEMAURL3_2_JSON !== schemaProps.$schema && SCHEMAURL3_2_XML !== schemaProps.$schema) // TODO: Allow for 3.x URI versions to allow the API to read newer specs. (Start at 3.2 though)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema ${this.name} has an unsupported namespace '${schemaProps.$schema}'.`);
if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)

Check failure

Code scanning / CodeQL

Useless regular-expression character escape High

The escape sequence '\.' is equivalent to just '.', so the sequence may still represent a meta-character when it is used in a
regular expression
.

Copilot Autofix AI about 15 hours ago

To fix the problem, we need to ensure that the backslashes are correctly escaped in the string literal so that they are interpreted correctly in the regular expression. Specifically, we need to replace \. with \\. in the string literals used to create the regular expressions. This ensures that the backslash is preserved and the period is treated as a literal character in the regular expression.

core/ecschema-metadata/src/Metadata/Schema.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/core/ecschema-metadata/src/Metadata/Schema.ts b/core/ecschema-metadata/src/Metadata/Schema.ts
--- a/core/ecschema-metadata/src/Metadata/Schema.ts
+++ b/core/ecschema-metadata/src/Metadata/Schema.ts
@@ -671,3 +671,3 @@
 
-    if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
+    if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
       throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
EOF
@@ -671,3 +671,3 @@

if (schemaProps.$schema.match(`https://dev\.bentley\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\.bentley\.com/schemas/Bentley\.ECXML\.([0-9]+)`) == null)
if (schemaProps.$schema.match(`https://dev\\.bentley\\.com/json_schemas/ec/([0-9]+)/ecschema`) == null && schemaProps.$schema.match(`http://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)`) == null)
throw new ECObjectsError(ECObjectsStatus.MissingSchemaUrl, `The Schema '${this.name}' has an unsupported namespace '${schemaProps.$schema}'.`);
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant