Skip to content

Commit

Permalink
🐛 fix handling of invalid IDNA labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret committed Feb 5, 2025
1 parent 7000bad commit 407fadb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.4.1 (2025-02-05)
====================

**Fixed**
- Bad IDNA label raise inappropriate exception.

1.4.0 (2025-02-05)
====================

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qh3"
version = "1.4.0"
version = "1.4.1"
edition = "2021"
rust-version = "1.75"
license = "BSD-3"
Expand Down
2 changes: 1 addition & 1 deletion qh3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .quic.packet import QuicProtocolVersion
from .tls import CipherSuite, SessionTicket

__version__ = "1.4.0"
__version__ = "1.4.1"

__all__ = (
"connect",
Expand Down
7 changes: 3 additions & 4 deletions src/intldomain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use pyo3::exceptions::PyUnicodeDecodeError;
use pyo3::exceptions::PyUnicodeEncodeError;
use pyo3::exceptions::PyValueError;
use pyo3::pyfunction;
use pyo3::types::PyBytesMethods;
use pyo3::types::{PyBytes, PyString};
Expand All @@ -13,7 +12,7 @@ use idna::domain_to_unicode;
pub fn idna_encode<'a>(py: Python<'a>, text: &str) -> PyResult<Bound<'a, PyBytes>> {
let idna_domain = match domain_to_ascii(text) {
Ok(s) => s,
Err(e) => return Err(PyUnicodeEncodeError::new_err(e.to_string())),
Err(e) => return Err(PyValueError::new_err(e.to_string())),
};

Ok(PyBytes::new(py, idna_domain.as_bytes()))
Expand All @@ -24,7 +23,7 @@ pub fn idna_decode<'a>(py: Python<'a>, src: Bound<'a, PyBytes>) -> PyResult<Boun
let decode_res = domain_to_unicode(std::str::from_utf8(src.as_bytes())?);

if decode_res.1.is_err() {
return Err(PyUnicodeDecodeError::new_err(""));
return Err(PyValueError::new_err("invalid IDNA input"));
}

Ok(PyString::new(py, decode_res.0.as_ref()))
Expand Down

0 comments on commit 407fadb

Please sign in to comment.