diff --git a/colorhash/matricizer.py b/colorhash/matricizer.py index d3186b0..b580c25 100644 --- a/colorhash/matricizer.py +++ b/colorhash/matricizer.py @@ -3,13 +3,16 @@ import abc import re from typing import Mapping, Sequence -from .palettes import Palette, DEFAULT_PALETTES, GRADIENT_PALETTES, MULTICOLOR_PALETTES - +from .palettes import (DEFAULT_PALETTES, GRADIENT_PALETTES, + MULTICOLOR_PALETTES, Palette) Matrix = Sequence[Sequence[int]] def detect_hash_algorithm(hash_or_algo: str | bytes) -> str | None: + """ + Detect the hash algorithm based on a string. + """ dimensions: Mapping[int, str] = { 32: "md5", 40: "sha1", @@ -22,6 +25,7 @@ def detect_hash_algorithm(hash_or_algo: str | bytes) -> str | None: return dimensions.get(len(hash_or_algo) * 2) hoa = hash_or_algo.lower() + if re.match(r"^([0-9a-fA-F]{2})+$", hoa): return dimensions.get(len(hoa)) elif hoa in list(dimensions.values()): diff --git a/examples/commithash.svg b/examples/commithash.svg index 82950b7..5a9d39e 100644 --- a/examples/commithash.svg +++ b/examples/commithash.svg @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file