Skip to content

parsing aliases with = inside them fails with ValueError: too many values to unpack #117

@kasimeka

Description

@kasimeka

resholve fails to parse aliases with = chars in their definition because aliases are split with .split('=') here, this breaks derivation realisation whether or not solutions.default.fix.aliases is set to true.

example alias that triggers the issue:

ssh_prod='ssh $(AWS_REGION=us-east-1 ssm-machine jump)'

error emitted during evaluation:

>   File "/nix/store/bmnmsvgqamwdcvybicmw5hkv1lanihnh-resholve-0.10.5/bin/.resholve-wrapped", line 3509, in handle_builtin_alias
>     alias, definition = word.strip("\"='").split("=")
> ValueError: too many values to unpack

patching resholve as follows to only split on the first occurrence of = fixed it for me, I'm willing to create a PR for this if you don't mind.

diff --git a/resholve b/resholve
index c163fa9..e0581bc 100755
--- a/resholve
+++ b/resholve
@@ -3506,7 +3506,7 @@ class RecordCommandlike(object):
             if word.ok:
                 # not dynamic; more examples in tests/aliases.sh, but:
                 # 'd', 'echo $SOURCE_DATE_EPOCH'
-                alias, definition = word.strip("\"='").split("=")
+                alias, definition = word.strip("\"='").split("=", 1)
                 # TODO: maybe below deserves an explicit API
                 cmdlikes[alias].alias = True
                 commandlike = definition.split()[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions