From b3a35e4df5e86437f51f1c20edb930d522421524 Mon Sep 17 00:00:00 2001 From: wangRan <307209868@qq.com> Date: Wed, 5 Dec 2018 17:47:53 +0800 Subject: [PATCH] fix: Boolean type resolution error in xml --- .../src/factory/common/ManagedResolverFactory.ts | 2 ++ packages/context/src/factory/common/constants.ts | 1 + .../context/test/fixtures/app/resources/object.xml | 1 + .../unit/factory/xml/XmlApplicationContext.test.ts | 1 + .../unit/factory/xml/XmlObjectElementParser.test.ts | 10 ++++++++++ 5 files changed, 15 insertions(+) diff --git a/packages/context/src/factory/common/ManagedResolverFactory.ts b/packages/context/src/factory/common/ManagedResolverFactory.ts index c8e77a4aab2f..70bc6aa1b97c 100644 --- a/packages/context/src/factory/common/ManagedResolverFactory.ts +++ b/packages/context/src/factory/common/ManagedResolverFactory.ts @@ -101,6 +101,8 @@ class ValueResolver extends BaseManagedResolver { return parseInt(tpl(mv.value, props), 10); case VALUE_TYPE.DATE: return new Date(tpl(mv.value, props)); + case VALUE_TYPE.BOOLEAN: + return mv.value === 'true'; } return mv.value; diff --git a/packages/context/src/factory/common/constants.ts b/packages/context/src/factory/common/constants.ts index 18c30d2029d4..d03c00407942 100644 --- a/packages/context/src/factory/common/constants.ts +++ b/packages/context/src/factory/common/constants.ts @@ -70,4 +70,5 @@ export const VALUE_TYPE = { TEMPLATE: 'template', MANAGED: 'managed', OBJECT: 'object', // 仅仅在解析时使用 + BOOLEAN: 'boolean' }; diff --git a/packages/context/test/fixtures/app/resources/object.xml b/packages/context/test/fixtures/app/resources/object.xml index 6be9992bd4e3..d1c7347fa192 100644 --- a/packages/context/test/fixtures/app/resources/object.xml +++ b/packages/context/test/fixtures/app/resources/object.xml @@ -7,6 +7,7 @@ + diff --git a/packages/context/test/unit/factory/xml/XmlApplicationContext.test.ts b/packages/context/test/unit/factory/xml/XmlApplicationContext.test.ts index 8d66da16e466..a90800697389 100644 --- a/packages/context/test/unit/factory/xml/XmlApplicationContext.test.ts +++ b/packages/context/test/unit/factory/xml/XmlApplicationContext.test.ts @@ -62,6 +62,7 @@ describe('/test/unit/factory/xml/XmlApplicationContext', () => { expect(foo.int === 12).true; expect(foo.date.getTime()).eq(1527069046019); expect(foo.unknow).eq('aaa'); + expect(foo.boolean).eq(true); }); it('injectionpoint should be ok', () => { const bar: any = ctx1.get('obj:bar'); diff --git a/packages/context/test/unit/factory/xml/XmlObjectElementParser.test.ts b/packages/context/test/unit/factory/xml/XmlObjectElementParser.test.ts index 642a0a55caef..24ca91775dfb 100644 --- a/packages/context/test/unit/factory/xml/XmlObjectElementParser.test.ts +++ b/packages/context/test/unit/factory/xml/XmlObjectElementParser.test.ts @@ -186,6 +186,16 @@ describe('/test/unit/factory/xml/XmlObjectElementParser', () => { expect(mp3.value.type).eq(KEYS.VALUE_ELEMENT); expect(mp3.value.value).eq('10'); expect(mp3.value.valueType).eq('int'); + + const s4 = ` + + true + + `; + const mp4 = parseStr(s4); + expect(mp4.value.type).eq(KEYS.VALUE_ELEMENT); + expect(mp4.value.value).eq('true'); + expect(mp4.value.valueType).eq('boolean'); }); it('props parser should ok', () => { const s = `