Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Make Typewiz robust to errors from .toString() user code #84

Closed
zxti opened this issue Nov 27, 2018 · 2 comments
Closed

Make Typewiz robust to errors from .toString() user code #84

zxti opened this issue Nov 27, 2018 · 2 comments
Assignees
Labels
bug Something isn't working component:core

Comments

@zxti
Copy link

zxti commented Nov 27, 2018

The value.toString() call below can cause Typewiz to crash, since user code can override .toString() with arbitrary broken code. I ran into this trying to use the Ant library, for instance—rc-editor-mention overrides the class method Mention.toString.

function getTypeName(value, nest = 0) {
       ...
        if (value instanceof Function) {
            let argsStr = value.toString().split('=>')[0];
@urish
Copy link
Collaborator

urish commented Nov 27, 2018

Good catch, the issue reproduces with the following test case (added inside type-collector-snippet.spec.ts):

            it('should gracefully deal with toString() method throwing an error', () => {
                function f() { /* noop */ }
                f.toString = () => { throw new Error('Dont call this method'); };

                expect($_$twiz.typeName(f)).toBe(
                    '() => any',
                );
            });

Would you be interested in working on a PR that fixes this?

@urish urish added bug Something isn't working component:core labels Nov 27, 2018
@urish urish self-assigned this Nov 28, 2018
@urish urish closed this as completed in a9f5642 Nov 28, 2018
@zxti
Copy link
Author

zxti commented Nov 29, 2018

Thanks for going ahead and fixing this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working component:core
Projects
None yet
Development

No branches or pull requests

2 participants