diff --git a/rendercv/cli/printer.py b/rendercv/cli/printer.py index bf92f4bc..525b5df2 100644 --- a/rendercv/cli/printer.py +++ b/rendercv/cli/printer.py @@ -226,6 +226,10 @@ def print_validation_errors(exception: pydantic.ValidationError): "This is not a valid date! Please use either YYYY-MM-DD, YYYY-MM, or YYYY" " format!" ), + "String should match pattern '\\b10\\..*'": ( + 'A DOI prefix should always start with "10.". For example,' + ' "10.1109/TASC.2023.3340648".' + ), "URL scheme should be 'http' or 'https'": "This is not a valid URL!", "Field required": "This field is required!", "value is not a valid phone number": "This is not a valid phone number!", diff --git a/rendercv/data/models/computers.py b/rendercv/data/models/computers.py index 70415021..490218dd 100644 --- a/rendercv/data/models/computers.py +++ b/rendercv/data/models/computers.py @@ -233,7 +233,7 @@ def make_a_url_clean(url: str) -> str: Returns: str: The clean URL. """ - url = url.replace("https://", "").replace("http://", "").replace("www.", "") + url = url.replace("https://", "").replace("http://", "") if url.endswith("/"): url = url[:-1] diff --git a/rendercv/data/models/entry_types.py b/rendercv/data/models/entry_types.py index 711a01c3..b9594a58 100644 --- a/rendercv/data/models/entry_types.py +++ b/rendercv/data/models/entry_types.py @@ -229,7 +229,7 @@ class PublicationEntryBase(RenderCVBaseModelWithExtraKeys): title="Authors", description="The authors of the publication in order as a list of strings.", ) - doi: Optional[str] = pydantic.Field( + doi: Optional[Annotated[str, pydantic.Field(pattern=r"\b10\..*")]] = pydantic.Field( default=None, title="DOI", description="The DOI of the publication.", @@ -252,8 +252,8 @@ class PublicationEntryBase(RenderCVBaseModelWithExtraKeys): def ignore_url_if_doi_is_given(self) -> "PublicationEntryBase": """Check if DOI is provided and ignore the URL if it is provided.""" doi_is_provided = self.doi is not None - url_is_provided = self.url is not None - if doi_is_provided and url_is_provided: + + if doi_is_provided: self.url = None return self @@ -278,7 +278,7 @@ class PublicationEntryBase(RenderCVBaseModelWithExtraKeys): url_is_provided = self.url is not None if url_is_provided: - return computers.make_a_url_clean(self.url) # type: ignore + return computers.make_a_url_clean(str(self.url)) # type: ignore else: return "" diff --git a/tests/test_data.py b/tests/test_data.py index 0ffa0edb..e22fd96a 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -767,3 +767,21 @@ def test_dictionary_key_to_proper_section_title(key, expected_section_title): # def test_if_available_themes_and_avaialble_theme_options_has_the_same_length(): + + +@pytest.mark.parametrize( + "url, expected_clean_url", + [ + ("https://example.com", "example.com"), + ("https://example.com/", "example.com"), + ("https://example.com/test", "example.com/test"), + ("https://example.com/test/", "example.com/test"), + ("https://www.example.com/test/", "www.example.com/test"), + ], +) +def test_make_a_url_clean(url, expected_clean_url): + assert computers.make_a_url_clean(url) == expected_clean_url + assert ( + data.PublicationEntry(title="Test", authors=["test"], url=url).clean_url + == expected_clean_url + )