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

escape literal percent sign when formatting #61523

Merged
merged 1 commit into from Mar 26, 2018

Conversation

@dixudx
Member

dixudx commented Mar 22, 2018

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #61503

Special notes for your reviewer:
/assign @janetkuo @liggitt
/cc @kubernetes/sig-cli-bugs

Release note:

escape literal percent sign when formatting
@@ -61,6 +61,8 @@ func (f *Formatter) WriteWrapped(str string, a ...interface{}) error {
text := fmt.Sprintf(str, a...)
strs := wrapString(text, f.Wrap-f.IndentLevel)
for _, substr := range strs {
// escape literal percent sign
substr = strings.Replace(substr, "%", "%%", -1)

This comment has been minimized.

@soltysh

soltysh Mar 22, 2018

Contributor

Mind adding a test case covering it?

This comment has been minimized.

@liggitt

liggitt Mar 22, 2018

Member

Hmm… are there other formatting directives that will cause issues? I'd prefer we stop treating this as a format string altogether than try to escape here for later layers

This comment has been minimized.

@apelisse

apelisse Mar 22, 2018

Member

Yeah, I think Jordan is right. I'd be better to just take a pre-formatted string, and call Sprintf from the caller, or maybe add a Writef for convenience.

@dixudx

This comment has been minimized.

Member

dixudx commented Mar 23, 2018

@soltysh @liggitt @apelisse Updated. PTAL. Thanks.

@@ -48,7 +48,11 @@ func (f *Formatter) Write(str string, a ...interface{}) error {
for i := 0; i < f.IndentLevel; i++ {
indent = indent + " "
}
_, err := io.WriteString(f.Writer, indent+fmt.Sprintf(str, a...)+"\n")
if a != nil {

This comment has been minimized.

@liggitt

liggitt Mar 23, 2018

Member

nit, len(a) > 0

This comment has been minimized.

@dixudx

dixudx Mar 23, 2018

Member

@liggitt Done. PTAL. Thanks.

@liggitt

This comment has been minimized.

Member

liggitt commented Mar 23, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Mar 23, 2018

@k8s-ci-robot

This comment has been minimized.

Contributor

k8s-ci-robot commented Mar 23, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dixudx, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-merge-robot

This comment has been minimized.

Contributor

k8s-merge-robot commented Mar 26, 2018

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-merge-robot

This comment has been minimized.

Contributor

k8s-merge-robot commented Mar 26, 2018

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-merge-robot k8s-merge-robot merged commit 3a2fe7b into kubernetes:master Mar 26, 2018

13 of 14 checks passed

Submit Queue Required Github CI test is not green: pull-kubernetes-e2e-gce
Details
cla/linuxfoundation dixudx authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce Job succeeded.
Details
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment