Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9720 from micalevisk/feat/repl-fix-injections
fix(core): prevent renaming global providers and modules in the repl
- Loading branch information
Showing
12 changed files
with
115 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Similar to `Object.assign` but copying properties descriptors from `source` | ||
* as well. | ||
*/ | ||
export function assignToObject<T, U>(target: T, source: U): T & U { | ||
Object.defineProperties( | ||
target, | ||
Object.keys(source).reduce((descriptors, key) => { | ||
descriptors[key] = Object.getOwnPropertyDescriptor(source, key); | ||
return descriptors; | ||
}, Object.create(null)), | ||
); | ||
return target as T & U; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect } from 'chai'; | ||
import { assignToObject } from '@nestjs/core/repl/assign-to-object.util'; | ||
|
||
describe('assignToObject', () => { | ||
it('should copy all enumerable properties and their descriptors', () => { | ||
const sourceObj = {}; | ||
Object.defineProperty(sourceObj, 'foo', { | ||
value: 123, | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
}); | ||
Object.defineProperty(sourceObj, 'bar', { | ||
value: 456, | ||
configurable: true, | ||
enumerable: true, | ||
writable: false, | ||
}); | ||
const targetObj = {}; | ||
|
||
assignToObject(targetObj, sourceObj); | ||
|
||
expect(Object.getOwnPropertyDescriptor(targetObj, 'foo')).to.be.eql({ | ||
value: 123, | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
}); | ||
expect(Object.getOwnPropertyDescriptor(targetObj, 'bar')).to.be.eql({ | ||
value: 456, | ||
configurable: true, | ||
enumerable: true, | ||
writable: false, | ||
}); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.