[edit] Support package with "=" in package name.
A package in the jiri manifest may contain character "=" in its
package name. For example:
fuchsia/third_party/android/aemu/release/${os=linux}-arm64
This didn't work when we updated the package name using the `jiri edit`
command, because `jiri edit` split the `package=version` command
argument from its first "=" character occurrence.
This change fixes the issue by splitting the command argument
from its last "=" character occurrence (the version string doesn't
contain "=" characters).
Bug: 325638229
Test: jiri edit -package 'fuchsia/third_party/android/aemu/release/${os=linux}-arm64=bid:11622403'
Change-Id: Ie7e6a258c1d54ba17a9ba50767e0f2d67744f5b9
Reviewed-on: https://fuchsia-review.googlesource.com/c/jiri/+/1014315
Reviewed-by: Oliver Newman <olivernewman@google.com>
Fuchsia-Auto-Submit: Yilong Li <liyl@google.com>
Commit-Queue: Yilong Li <liyl@google.com>
diff --git a/cmd/jiri/edit.go b/cmd/jiri/edit.go
index 2984cec..3b87b5a 100644
--- a/cmd/jiri/edit.go
+++ b/cmd/jiri/edit.go
@@ -144,11 +144,14 @@
}
}
for _, p := range editFlags.packages {
- s := strings.SplitN(p, "=", 2)
- if len(s) == 1 {
+ // The package name may contain "=" characters; so we split the string from the rightmost "=".
+ separatorPos := strings.LastIndex(p, "=");
+ if separatorPos == -1 || separatorPos == 0 || separatorPos == len(p) - 1 {
return jirix.UsageErrorf("Please provide the -package flag in the form <package-name>=<version>")
} else {
- packages[s[0]] = s[1]
+ packageName := p[:separatorPos]
+ version := p[separatorPos + 1:]
+ packages[packageName] = version
}
}