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

cli: Can't escape initial at (@) in parameter #2511

Closed
pyhedgehog opened this issue Mar 6, 2023 · 5 comments · Fixed by #2513
Closed

cli: Can't escape initial at (@) in parameter #2511

pyhedgehog opened this issue Mar 6, 2023 · 5 comments · Fixed by #2513

Comments

@pyhedgehog
Copy link
Contributor

Description

Symbol "@" in all parameter values parsed as file reference, and I found no way to override this behaviour.

python-gitlab/gitlab/cli.py

Lines 274 to 285 in 9c24657

def _parse_value(v: Any) -> Any:
if isinstance(v, str) and v.startswith("@"):
# If the user-provided value starts with @, we try to read the file
# path provided after @ as the real value. Exit on any error.
try:
with open(v[1:], encoding="utf-8") as f:
return f.read()
except Exception as e:
sys.stderr.write(f"{e}\n")
sys.exit(1)
return v

Expected Behavior

gitlab project-tag delete --project-id somenamespace/myproject --name '@at-started-tag'

Command executed without errors and tag is deleted.

Actual Behavior

$ gitlab project-tag delete --project-id somenamespace/myproject --name '@at-started-tag'
[Errno 2] No such file or directory: 'at-started-tag'
@pyhedgehog pyhedgehog changed the title Can't escape initial at (@) in parameter cli: Can't escape initial at (@) in parameter Mar 6, 2023
@JohnVillalovos
Copy link
Collaborator

Yes that does seem like a use-case not considered before. I'm not sure the best way to fix that.

My initial thought would be to be able to do: \@at-started-tag and the code could check for content starting with \@ and if so return back the value without the backslash.

@nejch Do you have any ideas?

@pyhedgehog
Copy link
Contributor Author

@JohnVillalovos as soon as this is place-specific escape (i.e. it should not be replaced anywhere else except string start) I'd prefer @@.

@nejch
Copy link
Member

nejch commented Mar 10, 2023

A bit late to the party here sorry folks! :) @JohnVillalovos @pyhedgehog I like the idea with an escape character and \ is more standard. Although @@ does look a bit more pleasing visually and is consistent with GitLab's double-escaping dollar signs in variables (https://docs.gitlab.com/ee/ci/variables/#use-the--character-in-cicd-variables). So maybe we could go with that.

@pyhedgehog
Copy link
Contributor Author

@nejch It's in line with $$ in gitlab CICD, docker-compose.yml, and '' in SQL strings. :-)
If you like this, you can just approve my PR. If you prefer backslash tell me, i'll change my PR.

@JohnVillalovos
Copy link
Collaborator

I'm perfectly fine with @@

nejch added a commit that referenced this issue Mar 11, 2023
* fix(cli): Add ability to escape at-prefixed parameter (#2511)

---------

Co-authored-by: Nejc Habjan <hab.nejc@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants