fix cloneObject() function to respect RegExp (#3240)

fixes #3237
This commit is contained in:
Karsten Hassel 2023-10-19 22:31:02 +02:00 committed by GitHub
parent a0b444d6c4
commit 0e2da630d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View file

@ -21,6 +21,7 @@ _This release is scheduled to be released on 2024-01-01._
- Fix the option eventClass on customEvents.
- Fix yr API version in locationforecast call (#3227)
- Fix cloneObject() function to respect RegExp (#3237)
## [2.25.0] - 2023-10-01

View file

@ -90,6 +90,10 @@ function cloneObject(obj) {
return obj;
}
if (obj.constructor.name === "RegExp") {
return new RegExp(obj);
}
const temp = obj.constructor(); // give temp the original obj's constructor
for (const key in obj) {
temp[key] = cloneObject(obj[key]);

View file

@ -49,6 +49,13 @@ describe("File js/class", () => {
expect(obj).toBe(expected);
});
it("should clone regex", () => {
const expected = /.*Magic/;
const obj = clone(expected);
expect(obj).toEqual(expected);
expect(expected === obj).toBe(false);
});
it("should clone undefined", () => {
const expected = undefined;
const obj = clone(expected);