Skip to content

#794 breaks access properties of URL objects #811

Description

@PeterZhenhh

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+)

undefined
undefined

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions