Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permetre especificar noms de projectes amb espais i altres caràcters #314

Closed
pereorga opened this issue Aug 29, 2023 · 2 comments
Closed

Comments

@pereorga
Copy link
Member

pereorga commented Aug 29, 2023

Depenent de com es configuri un projecte, el fet que el nom del projecte contingui espais o altres caràcters (com la cometa simple) fa que el procés falli. Això és un problema, ja que el nom del projecte s'hauria de poder especificar literalment.

Reportat abans a #313 i #307.

Per exemple, això falla:

{
    "project": "Andor's Trail",
    "license" : "GPL-2.0-only",
    "projectweb": "https://hosted.weblate.org/projects/andors-trail/-/ca/",
    "fileset": {
        "Andors Trail": {
            "url": "https://hosted.weblate.org/download/andors-trail/-/ca/?format=zip",
            "type": "compressed",
            "target": "ca.zip"
        }
    }
}

Això també em falla:

{
    "project": "OBS Studio",
    "license" : "GPL-2.0-or-later",
    "projectweb": "https://crowdin.com/project/obs-studio",
    "fileset": {
        "OBSStudio": {
            "url": "https://github.com/obsproject/obs-studio.git",
            "type": "git"
        }
    }
}

En Bash això és un problema típic quan, per exemple, s'incorpora una variable sense rodejar-la de cometes. Suposo que abans de fer servir el nom del projecte, es podria "sanititzar" en python (només és un exemple, no sé com s'hauria d'aplicar al codi):

import string

def sanitize_filename(filename):
    """
    Sanitize a string to be used as a filename.
    Remove characters that are not safe for file systems and replace them with underscores.
    """
    
    # Define characters that are valid
    valid_chars = "-_.()%s%s" % (string.ascii_letters, string.digits)
    
    # Replace invalid characters with underscores
    sanitized = ''.join(c if c in valid_chars else '_' for c in filename)
    
    # To further prevent edge cases, ensure the resulting name doesn't start with a dot
    if sanitized.startswith('.'):
        sanitized = '_' + sanitized[1:]
    
    return sanitized

# Test
filename = "my:invalid//file name?.txt"
print(sanitize_filename(filename))  # Expected output: "my_invalid__file_name_.txt"
@jordimas
Copy link
Contributor

Ho miro, per informar d'error no ho facis en les PR perquè sinó quan es fa merge es perd. Millor informes d'error com aquest.

@jordimas
Copy link
Contributor

Bé Git ha tancat això sol amb el commit. Si veus que no funciona torna'l a obrir si us plau.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants