Skip to content

Commit

Permalink
feat(core): ignore quotation mark in git user/email config (#2537)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Dec 22, 2021
1 parent 0b06d8e commit e70481c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions renku/core/metadata/repository.py
Expand Up @@ -589,6 +589,9 @@ def _get_user_from_configuration(configuration: "Configuration") -> "Actor":
if not email: # pragma: no cover
raise errors.GitMissingEmail

name = _sanitize_git_config_value(name)
email = _sanitize_git_config_value(email)

return Actor(name=name, email=email)

def get_configuration(self, writable=False, scope: str = None) -> "Configuration":
Expand Down Expand Up @@ -1376,3 +1379,8 @@ def get_previous_commit_from_submodules() -> Optional[Commit]:

if submodules:
return get_previous_commit_from_submodules()


def _sanitize_git_config_value(value: str) -> str:
"""Remove quotation marks and whitespaces surrounding a config value."""
return value.strip(" \n\t\"'")
12 changes: 12 additions & 0 deletions tests/core/metadata/test_repository.py
Expand Up @@ -227,3 +227,15 @@ def test_hash_directories(git_repository):

with pytest.raises(errors.GitCommandError):
Repository.hash_object("X")


def test_get_user_with_quotation_mark(git_repository):
"""Test quotation marks wrapping user/email are ignored."""
config = git_repository.get_configuration(writable=True)
config.set_value("user", "name", """ ' Renku the Frog' """)
config.set_value("user", "email", """ "renku@renku.ch " """)

user = git_repository.get_user()

assert "Renku the Frog" == user.name
assert "renku@renku.ch" == user.email

0 comments on commit e70481c

Please sign in to comment.