Summary
After upgrading from 2.1.1 to 2.2.0+ (including 2.2.1), JSONata can no longer access properties of JavaScript URL objects.
This worked correctly in 2.1.1.
Reproduction
import jsonata from "jsonata";
const url = new URL("http://xxx.com/json/favicon.ico");
console.log(await jsonata("hostname").evaluate(url));
console.log(await jsonata("href").evaluate(url));
Expected (v2.1.1)
xxx.com
http://xxx.com/json/favicon.ico
Actual (v2.2.0+)
The URL object is valid:
console.log(url instanceof URL); // true
console.log(url.hostname); // "xxx.com"
Possible cause
It appears this change introduced the regression:
Before (v2.1.1):
} else if (input !== null && typeof input === 'object' && !isFunction(input)) {
After (v2.2.0):
} else if (
input !== null &&
typeof input === 'object' &&
Object.prototype.hasOwnProperty.call(input, key) &&
!isFunction(input)
) {
URL.hostname, URL.href, etc. are exposed through prototype getters rather than own properties, so hasOwnProperty() returns false.
As a result, JSONata no longer resolves these properties.
Question
Was this behavior change intentional?
If so, is there a recommended way to access properties from JavaScript built-in objects such as URL?
Summary
After upgrading from 2.1.1 to 2.2.0+ (including 2.2.1), JSONata can no longer access properties of JavaScript
URLobjects.This worked correctly in 2.1.1.
Reproduction
Expected (v2.1.1)
Actual (v2.2.0+)
The
URLobject is valid:Possible cause
It appears this change introduced the regression:
Before (v2.1.1):
After (v2.2.0):
URL.hostname,URL.href, etc. are exposed through prototype getters rather than own properties, sohasOwnProperty()returnsfalse.As a result, JSONata no longer resolves these properties.
Question
Was this behavior change intentional?
If so, is there a recommended way to access properties from JavaScript built-in objects such as
URL?