-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: properly support spaces in string values #27
Conversation
please just add comments everywhere explaining why this stuff is being done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with few minor comments
@@ -92,7 +95,8 @@ public String getAttribute(Path bazelBuildFile, String target, String attribute) | |||
// immediately. | |||
public void setAttribute(Path bazelBuildFile, String target, String attribute, String value) | |||
throws IOException { | |||
execute(bazelBuildFile, String.format("set %s \"%s\"", attribute, value), target); | |||
final String escapedValue = value.replace(" ", "\\ "); | |||
execute(bazelBuildFile, String.format("set %s \"%s\"", attribute, escapedValue), target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: just inlining replace call here would be just fine.
On a side note, it feels like setAttribute()
, addAttribute()
, batchSetAttribute()
, batchAddAttribute()
could become a one method, with an argument maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what, we don't need non-batch methods at all. We don't use them anywhere so YAGNI. They are terribly slow since they execute buildozer
for each invocation.
@@ -82,6 +82,9 @@ public String getAttribute(Path bazelBuildFile, String target, String attribute) | |||
if (value.equals("(missing)")) { | |||
return null; | |||
} | |||
if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') { | |||
value = value.substring(1, value.length() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to be related to the spaces issue. How did this thing work before and why is it needed?
Minor: another lazy option of doign it coudl be value.startsWith("\"") && value.endsWith("\"")
, though the currenv version is more "performant" as it works directly with characters (pretending like it matters here...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is related. I will add a comment :) The thing is:
fenster@fenster ws:~/googleapis$ buildozer 'print ruby_cloud_title' //google/api/servicecontrol/v1:servicecontrol_ruby_gapic
"Service Control API V1"
fenster@fenster ws:~/googleapis$ buildozer 'print name' //google/api/servicecontrol/v1:servicecontrol_ruby_gapic
servicecontrol_ruby_gapic
So it adds quotes if the string has spaces inside. We don't need those quotes, so I'm stripping them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment
Some values can have spaces in them. For such strings,
buildozer print
returns a"string in quotes"
, but to write them back, we"must\ quote\ spaces"
. Weird it is.