Skip to content

Commit

Permalink
fix(utils): Modify getOwnPropertyDescriptor to hasOwnProperty prototy…
Browse files Browse the repository at this point in the history
…pe function
  • Loading branch information
ssi02014 committed Jan 29, 2024
1 parent 9a1ba81 commit aa4c194
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 19 deletions.
9 changes: 5 additions & 4 deletions dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function addToSet(set, array) {
*/
function cleanArray(array) {
for (let index = 0; index < array.length; index++) {
if (getOwnPropertyDescriptor(array, index) === undefined) {
const isHasOwnProperty = Object.prototype.hasOwnProperty.call(array, index);
if (!isHasOwnProperty) {
array[index] = null;
}
}
Expand All @@ -136,7 +137,8 @@ function cleanArray(array) {
function clone(object) {
const newObject = create(null);
for (const [property, value] of entries(object)) {
if (getOwnPropertyDescriptor(object, property) !== undefined) {
const isHasOwnProperty = Object.prototype.hasOwnProperty.call(object, property);
if (isHasOwnProperty) {
if (Array.isArray(value)) {
newObject[property] = cleanArray(value);
} else if (value && typeof value === 'object' && value.constructor === Object) {
Expand Down Expand Up @@ -169,8 +171,7 @@ function lookupGetter(object, prop) {
}
object = getPrototypeOf(object);
}
function fallbackValue(element) {
console.warn('fallback value for', element);
function fallbackValue() {
return null;
}
return fallbackValue;
Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ function addToSet(set, array, transformCaseFunc = stringToLowerCase) {
*/
function cleanArray(array) {
for (let index = 0; index < array.length; index++) {
if (getOwnPropertyDescriptor(array, index) === undefined) {
const isHasOwnProperty = Object.prototype.hasOwnProperty.call(array, index);

if (!isHasOwnProperty) {
array[index] = null;
}
}
Expand All @@ -133,7 +135,12 @@ function clone(object) {
const newObject = create(null);

for (const [property, value] of entries(object)) {
if (getOwnPropertyDescriptor(object, property) !== undefined) {
const isHasOwnProperty = Object.prototype.hasOwnProperty.call(
object,
property
);

if (isHasOwnProperty) {
if (Array.isArray(value)) {
newObject[property] = cleanArray(value);
} else if (
Expand Down

0 comments on commit aa4c194

Please sign in to comment.