fix(core): stringify shouldn't throw when toString returns null/undefined (#14975)
Fixes #14948 PR Close #14975
This commit is contained in:
parent
0759911431
commit
8e6995c91e
|
@ -69,6 +69,11 @@ export function stringify(token: any): string {
|
|||
}
|
||||
|
||||
const res = token.toString();
|
||||
|
||||
if (res == null) {
|
||||
return '' + res;
|
||||
}
|
||||
|
||||
const newLineIndex = res.indexOf('\n');
|
||||
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {stringify} from '../src/util';
|
||||
|
||||
export function main() {
|
||||
describe('stringify', () => {
|
||||
it('should return string undefined when toString returns undefined',
|
||||
() => expect(stringify({toString: (): string => undefined})).toBe('undefined'));
|
||||
|
||||
it('should return string null when toString returns null',
|
||||
() => expect(stringify({toString: (): string => null})).toBe('null'));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue