Repository navigation
Commit 28f8a62
fix(server): match input modes on type and subtype, ignoring case (a2aproject#1425)
# Description
With `validate_input_modes=True`, a card that declares `text/plain`
rejects a part sent as `Text/Plain` or `text/plain; charset=utf-8`,
because the check compares exact strings. The
[spec](https://github.com/a2aproject/A2A/blob/4735f4876449c6f381825d8a841b31b16c6ad0c4/specification/a2a.proto#L387)
defines input modes as media types, RFC 2045 section 5.1 makes type and
subtype case-insensitive, and a charset parameter does not change the
type.
The validator now compares lower-cased `type/subtype` on both sides. The
error still quotes what the client sent and what the card declares, and
`text/html; charset=utf-8` still fails against `text/plain`.
```
$ uv run pytest tests/utils/test_input_mode_validator.py # 11f1116, fix reverted
FAILED ...::test_media_types_match_on_type_and_subtype[Text/Plain-text/plain]
FAILED ...::test_media_types_match_on_type_and_subtype[text/plain; charset=utf-8-text/plain]
5 failed, 12 passed in 0.12s
$ uv run pytest # 11f1116 plus this branch, Python 3.10
2530 passed, 207 skipped, 4 xfailed, 1 xpassed, 200 warnings in 44.04s
$ uv run pytest --cov=src
src/a2a/utils/input_mode_validator.py 100%
TOTAL 94%
$ ./scripts/lint.sh
SUCCESS: All linting and formatting tasks complete!
# its 3 ruff diagnostics are in client_factory.py and transports/__init__.py, which this does not touch
```
a2aproject/a2a-js#745 still compares exact strings, so the two SDKs
differ until it gets the same fix, which I can send there next.
@mykytanetipa a card that declares `image/*` still only matches that
literal string. I kept wildcards out, since that is a policy call on top
of a2aproject#1269 rather than a parsing fix. Would you rather have them handled
here?
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [x] Appropriate docs were updated (if necessary)
- The `validate_input_modes` docstring now states the matching rule.
Refs a2aproject#1269. No issue exists, since the tests above reproduce it.
Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
Co-authored-by: Mateusz Iwaniuk <45974414+Iwaniukooo11@users.noreply.github.com>1 parent 58788bb commit 28f8a62
2 files changed
Lines changed: 44 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | | - | |
| 28 | + | |
25 | 29 | | |
26 | | - | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
31 | | - | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
35 | | - | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
0 commit comments