-
Notifications
You must be signed in to change notification settings - Fork 210
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
base: master
Are you sure you want to change the base?
Conversation
|
||
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
here
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R24
@@ -23,3 +23,3 @@ | ||
|
||
const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec"; | ||
const SCHEMAURL_JSON = "https://dev\\.bentley\\.com/json_schemas/ec"; | ||
|
|
||
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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R24
@@ -23,3 +23,3 @@ | ||
|
||
const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec"; | ||
const SCHEMAURL_JSON = "https://dev.bentley.com/json_schemas/ec"; | ||
|
|
||
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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R24
@@ -23,3 +23,3 @@ | ||
|
||
const SCHEMAURL_JSON = "https://dev\.bentley\.com/json_schemas/ec"; | ||
const SCHEMAURL_JSON = "https://dev.bentley.com/json_schemas/ec"; | ||
|
@@ -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
regular expression
Show autofix suggestion
Hide autofix suggestion
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
tohttps://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]+)
tohttp://www\\.bentley\\.com/schemas/Bentley\\.ECXML\\.([0-9]+)
.
-
Copy modified line R672
@@ -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}'.`); |
@@ -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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R672
@@ -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}'.`); |
@@ -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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R672
@@ -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}'.`); |
@@ -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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R672
@@ -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}'.`); |
@@ -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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R672
@@ -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}'.`); |
@@ -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
regular expression
Show autofix suggestion
Hide autofix suggestion
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.
-
Copy modified line R672
@@ -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}'.`); |
WIP