Skip to content

Commit

Permalink
Merge pull request #10 from amaabca/handle-readonly-attributes
Browse files Browse the repository at this point in the history
Handle readonly attributes
  • Loading branch information
MathieuGilbert authored Jul 15, 2019
2 parents e8c6280 + 6ab6b18 commit dc6ceec
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 78 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
language: node_js
node_js:
- "8.11.0"
- "8"
- "10"
- "11"
- "12"
cache:
yarn: true
directories:
- node_modules

script:
- yarn lint
- yarn test --ci
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"scripts": {
"lint": "eslint ./src ./test",
"test": "jest --coverage && yarn lint"
"pretest": "yarn lint",
"test": "jest --coverage"
},
"jest": {
"collectCoverage": true,
Expand Down
35 changes: 24 additions & 11 deletions src/sensitiveParamFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ class SensitiveParamFilter {
}

recursiveFilter(input) {
if (typeof input === 'string' || input instanceof String) {
if (!input || typeof input === 'number' || typeof input === 'boolean') {
return input
} else if (typeof input === 'string' || input instanceof String) {
return this.filterString(input)
} else if (input instanceof Error) {
return this.filterError(input)
} else if (input && typeof input === 'object' && input.constructor === Object) {
return this.filterObject(input)
} else if (Array.isArray(input)) {
return this.filterArray(input)
} else if (typeof input === 'object') {
return this.filterObject(input)
}
return input

return null
}

filterString(input) {
Expand All @@ -53,16 +56,26 @@ class SensitiveParamFilter {
if (id || id === 0) {
return this.examinedObjects[id].copy
}
let copy = null
try {
copy = new input.constructor(input.message)
} catch (error) {
copy = new Error(input.message)
}
copy.stack = input.stack

const copy = new Error(input.message)
Object.defineProperties(copy, {
name: {
configurable: true,
enumerable: false,
value: input.name,
writable: true
},
stack: {
configurable: true,
enumerable: false,
value: input.stack,
writable: true
}
})
if (input.code) {
copy.code = input.code
}

for (const key in input) { // eslint-disable-line guard-for-in
copy[key] = input[key]
}
Expand Down
Loading

0 comments on commit dc6ceec

Please sign in to comment.