with_path silently promotes a bare-relative URL to an absolute-path reference
- Lenguaje dominante
- Python
- Estrellas
- 1.5k
- Forks
- 215
- Merge medio
- 1 d 2 min
- PR fusionados (30 d)
- 13
Descripción
When is called with a path that does not start with on a bare-relative URL (e.g. ), the method unconditionally prepends , silently turning a path-relative reference into an absolute-path reference. The result resolves differently against any base URL.
### Repro
```python
>>> from yarl import URL
>>> url = URL('foo/bar')
>>> str(url.with_path('abs'))
'/abs' # should be 'abs' — the URL is bare-relative, not absolute
>>> url.with_path('abs').is_absolute()
True # was False before .with_path()
```
### Expected
The path's leading slash status should be preserved across for URLs without a netloc: a bare-relative URL stays bare-relative unless the caller explicitly passes a slash-prefixed path.
### Workaround
Pass an explicit to keep the slash-prefixed result (this case still works). The fix preserves that behavior.
### Risk
Any caller relying on the old behavior of getting back when passing to a bare-relative URL will see a behavior change. That caller can pass explicitly to opt in.
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.