An empty list or mapping is expanded as a defined value: `{x,v}` with `v=[]` gives `1,`, `{#v}` gives `#`, `{;v}` gives `;v=`
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 78/100
Rechercherichtung
Lies uritemplate/variable.py, insbesondere _string_expansion und _semi_path_expansion, und vergleiche deren Behandlung leerer Listen und Mappings mit _query_expansion und _label_path_expansion. Reproduziere die gemeldeten Fälle mit dem Python-Befehl aus dem Issue und führe anschließend die Testsuiten des Projekts und des RFC uritemplate-test aus. Fertig ist die Arbeit, wenn leere Collections in den betroffenen Expansionen als undefiniert behandelt werden und die aufgeführten erwarteten Ausgaben stimmen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Versions tested: uritemplate 4.2.0 from PyPI (the newest release on 2026-10-23) and the main branch at
8e46228e5a1ad3f688b21c6b3917d15dd0f7c581 (its head on 2026-10-23); CPython 3.10 and 3.11 on Linux.
Reproduce (one command):
python3 -c 'from uritemplate import expand; print(repr(expand("{x,v}", {"x": "1", "v": []})))'
An empty list is an ordinary value for a variable that has none to give, and RFC 6570 covers it.
Expected: '1'. RFC 6570 section 2.3: "A variable defined as a list value is considered undefined if the list contains zero members. A
variable defined as an associative array of (name, value) pairs is considered undefined if the array contains zero members or if all member
names in the array are associated with undefined values." Section 3.2.1: "A variable that is undefined (Section 2.3) has no value and is ignored by the expansion process. If all of the
variables in an expression are undefined, then the expression's expansion is the empty string." The algorithm in Appendix A says the same:
"If the varname is unknown or corresponds to a variable with an undefined value (Section 2.3), then skip to the next varspec". The separator
is appended only between defined variables.
Observed (the same on 4.2.0 and on main):
'1,'
More cases, all with x="1" (tool output / what the RFC text gives):
| template | v | observed | expected |
|---|---|---|---|
{+x,v} |
[] |
1, |
1 |
{#x,v} |
[] |
#1, |
#1 |
{#v} |
[] or {} |
# |
(empty) |
{;x,v} |
[] |
;x=1;v= |
;x=1 |
{;v} |
{} |
;v= |
(empty) |
{;v*} |
{} |
; |
(empty) |
Controls, correct today: {/x,v} -> /1, {.x,v} -> .1, {?x,v} -> ?x=1, {&x,v} -> &x=1, and {x,w} with w not given -> 1.
Where
In uritemplate/variable.py (same on main and in 4.2.0), _query_expansion returns None for an empty list or mapping (if not value: return None, in both the list and the mapping branch) and _label_path_expansion does the same (len(value) == 0), which is why /, ., ? and & are correct. _string_expansion (used by the simple, + and # operators) has no such check, and _semi_path_expansion has it only in its list-explode branch ({;v*} with [] correctly gives ''), so in the other cases the empty collection is expanded as a defined, empty value. Adding the same early return to those two functions made every case above agree with the RFC text and left the project's own test suite and the RFC's uritemplate-test suite green on this machine; that is only a local check, not a proposed patch.
Found by comparing the library with a small model of the RFC's expansion algorithm on generated templates and values, then confirmed against an independent implementation (uri-template 1.3.0 on PyPI), which gives '1', '' and ';v' for the three cases.
- Vorherrschende Sprache
- Python
- Sterne
- 246
- Forks
- 41
- Ø Merge
- 8 Std. 20 Min.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-hyper/uritemplate
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
python-hyper/uritemplate#163 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
python-hyper/uritemplate#51 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
python-hyper/uritemplate#34 · 4 Kommentare ·
-
Provide an API for validating URI TemplatesEvtl. vergeben @sigmavirus24 hat das vor 3380 Tagen übernommen. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
python-hyper/uritemplate#33 · 9 Kommentare ·
-
Add Contributor CovenantOffenenhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 45/100
python-hyper/uritemplate#15 ·
Alle Issues in python-hyper/uritemplate
Ähnliche Issues
-
style: article/section 📝 system: cloud.rc ☁️ system: security 🔐
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
uabrc/uabrc.github.io#1262 ·
-
documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
NCAR/miles-credit#526 ·
-
documentation
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 76/100
conda/conda-lock#957 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Type: Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
aws-samples/sample-per-model-bedrock#464 ·
Maintainer antworten meist innerhalb von 1 Tag