Skip to content

Commit

Permalink
fix: Boolean type resolution error in xml
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-ran committed Dec 5, 2018
1 parent 8f59981 commit b3a35e4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/context/src/factory/common/ManagedResolverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/context/src/factory/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ export const VALUE_TYPE = {
TEMPLATE: 'template',
MANAGED: 'managed',
OBJECT: 'object', // 仅仅在解析时使用
BOOLEAN: 'boolean'
};
1 change: 1 addition & 0 deletions packages/context/test/fixtures/app/resources/object.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<property name="int" value="12" type="int" />
<property name="date" value="2018-05-23T09:50:46.019Z" type="date" />
<property name="unknow" value="aaa" type="unknow" />
<property name="boolean" value="true" type="boolean" />
</object>
<!-- object at path -->
<object id="cowboy">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<property name="a">
<value type="boolean">true</value>
</property>
`;
const mp4 = <ManagedProperty>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 = `
Expand Down

0 comments on commit b3a35e4

Please sign in to comment.