Skip to content

Commit

Permalink
fix(koishi): parse element into inner, fix #1400
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 16, 2024
1 parent e4fe81b commit eb7714a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class Commander {

private defineElementDomain(name: keyof Argv.Domain, key = name, type = name) {
this.domain(name, (source, session) => {
const code = h.from(source)
const code = h.from(source, { type })
if (code && code.type === type) {
return code.attrs
}
Expand Down
9 changes: 9 additions & 0 deletions packages/core/tests/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@ describe('Parser API', () => {
expect(cmd.parse('-- "foo;bar";baz', ';')).to.have.shape({ options: { rest: '"foo;bar"' }, rest: 'baz' })
})
})

describe('Types', () => {
it('img', () => {
cmd = app.command('img <img:img>')
expect(cmd.parse('<img src="/"/>')).to.have.shape({ args: [{ src: '/' }] })
expect(cmd.parse('<p></p>')).to.have.shape({ 'error': 'internal.invalid-argument' })
expect(cmd.parse('<p><img src="/"/></p>')).to.have.shape({ args: [{ src: '/' }] })
})
})
})

0 comments on commit eb7714a

Please sign in to comment.