From cd439c04f305e323865e87940266c7764ade1731 Mon Sep 17 00:00:00 2001 From: Fengyuan Chen Date: Mon, 5 Sep 2022 23:30:46 +0800 Subject: [PATCH] fix(utils): avoid getting unexpected value (#11010) For example, when calling `get({}, 'button.small')`, it expects to return an empty string, but return a function (`''.small` is a native function, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/small). --- packages/vant/src/utils/basic.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vant/src/utils/basic.ts b/packages/vant/src/utils/basic.ts index 51093d73e..c280e6bc1 100644 --- a/packages/vant/src/utils/basic.ts +++ b/packages/vant/src/utils/basic.ts @@ -1,3 +1,4 @@ +import { isObject } from './validate'; import type { ComponentPublicInstance } from 'vue'; export function noop() {} @@ -16,7 +17,7 @@ export function get(object: any, path: string): any { let result = object; keys.forEach((key) => { - result = result[key] ?? ''; + result = isObject(result) ? result[key] ?? '' : ''; }); return result;