Skip to content

Commit

Permalink
Fixed prefix extraction during normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Jan 24, 2024
1 parent abdcfcd commit 33f36ff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [1.0.8] - Unreleased
- Import from pydantic v2 lib first
- Fixed prefix extraction during normalization

## [1.0.7] - 2024-01-07
- Support pydantic v1 & v2
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [1.0.8] - Unreleased
- Import from pydantic v2 lib first
- Fixed prefix extraction during normalization

## [1.0.7] - 2024-01-07
- Support pydantic v1 & v2
Expand Down
2 changes: 1 addition & 1 deletion iscc_core/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def iscc_normalize(iscc_code):
raise ValueError(f"Malformed multiformat codec: {decoded[:2]}")
iscc_code = encode_base32(decoded[2:])
else:
prefix = iscc_code.lstrip("ISCC:").lstrip("iscc:")[:2].upper()
prefix = iscc_code.upper().replace("ISCC:", "")[:2]
if prefix not in PREFIXES:
raise ValueError(f"ISCC starts with invalid prefix {prefix}")

Expand Down
5 changes: 5 additions & 0 deletions tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def test_Code_rnd():
assert ic.Code.rnd(ic.MT.DATA).maintype == ic.MT.DATA


def test_nomralize_roundtrip():
code = "ISCC:IABTRD3EMDL2W74Z4ROZTOJTT3BDY"
assert ic.iscc_normalize(code) == code


def test_noramlize_bad_prefix():
with pytest.raises(ValueError):
ic.iscc_normalize("ISCC:LA22222222")
Expand Down

0 comments on commit 33f36ff

Please sign in to comment.