Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyrit/converter/unicode_sub_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def __init__(self, *, start_value: int = 0xE0000) -> None:

Args:
start_value (int): The unicode starting point to use for encoding.

Raises:
ValueError: If ``start_value`` is outside the Unicode code point range.
"""
if not 0 <= start_value <= 0x10FFFF:
raise ValueError("start_value must be a valid Unicode code point between 0 and 0x10FFFF")
self.startValue = start_value

def _build_identifier(self) -> ComponentIdentifier:
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/converter/test_unicode_sub_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ async def test_unicode_sub_custom_start():
assert result.output_type == "text"


@pytest.mark.parametrize("start_value", [-1, 0x110000])
def test_unicode_sub_rejects_invalid_start_value(start_value):
with pytest.raises(ValueError, match="valid Unicode code point"):
UnicodeSubstitutionConverter(start_value=start_value)


async def test_unicode_sub_empty():
converter = UnicodeSubstitutionConverter()
result = await converter.convert_async(prompt="", input_type="text")
Expand Down