diff --git a/__tests__/utils/tpl-builtin.test.ts b/__tests__/utils/tpl-builtin.test.ts index 6a081dce..61061c63 100644 --- a/__tests__/utils/tpl-builtin.test.ts +++ b/__tests__/utils/tpl-builtin.test.ts @@ -1,7 +1,8 @@ import { prettyBytes, escapeHtml, - formatDuration + formatDuration, + resolveVariableAndFilter } from '../../src/utils/tpl-builtin'; test('tpl-builtin:prettyBytes', () => { @@ -18,5 +19,20 @@ test('tpl-builtin:formatDuration', () => { expect(formatDuration(1)).toEqual('1秒'); expect(formatDuration(61)).toEqual('1分1秒'); expect(formatDuration(233233)).toEqual('3天17时47分13秒'); +}) -}) \ No newline at end of file +test('tpl-bultin:resolveVariableAndFilter', () => { + const data = { + a: 1, + b: '2', + c: { + '1': 'first', + '2': 'second' + } + }; + + expect(resolveVariableAndFilter('${a}', data, '| raw')).toEqual(1); + expect(resolveVariableAndFilter('${b}', data, '| raw')).toEqual('2'); + expect(resolveVariableAndFilter('${c.${a}}', data, '| raw')).toEqual('first'); + expect(resolveVariableAndFilter('${c.${b}}', data, '| raw')).toEqual('second'); +}); \ No newline at end of file diff --git a/src/utils/tpl-builtin.ts b/src/utils/tpl-builtin.ts index ebf7f19e..a5301bc2 100644 --- a/src/utils/tpl-builtin.ts +++ b/src/utils/tpl-builtin.ts @@ -312,7 +312,7 @@ export const resolveVariableAndFilter = ( return undefined; } - const m = /^(\\)?\$(?:([a-z0-9_.]+)|{([^}{]+)})$/i.exec(path); + const m = /^(\\)?\$(?:([a-z0-9_.]+)|{([\s\S]+)})$/i.exec(path); if (!m) { return undefined;