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

Accept bytes as base64-encoded string by default #631

Merged
merged 3 commits into from
Feb 26, 2023

Conversation

flokli
Copy link
Contributor

@flokli flokli commented Feb 6, 2023

As per #611 (comment), this keeps thing symmetrical with the output, and how grpcurl handles it as well.

The old quoted literal behaviour is still accessible via --bytes-as-quoted-literals.

@codecov
Copy link

codecov bot commented Feb 6, 2023

Codecov Report

Merging #631 (f7bd8d2) into master (5f3b4c5) will decrease coverage by 0.11%.
The diff coverage is 62.22%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #631      +/-   ##
==========================================
- Coverage   80.01%   79.90%   -0.11%     
==========================================
  Files          57       57              
  Lines        3858     3882      +24     
==========================================
+ Hits         3087     3102      +15     
- Misses        542      548       +6     
- Partials      229      232       +3     

Copy link
Owner

@ktr0731 ktr0731 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I suggested one.

if err == nil {
return b, nil
}
if r.opts.BytesAsQuotedLiterals {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using a fallback to parse as quoted literals instead of adding a new option when the input string isn't Base64-encoded?
Current changes in this PR break backward compatibility; users who input quoted literals are affected by this behavior. I want to keep the same behavior if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add a fallback - I'd parsing as base64 is not possible, try to parse as quoted literal.

IMHO, the problem is that it's not always certain - a inserted string might parse as both base64 or quoted literal.

As a user, you want to be certain how the data you send should be interpreted - that's why I added a --bytes-as-quoted-literals mode, so it needs to be explicitly selected.

Making base64 the default input encoding for bytes makes more sense, because it's consistent with the output.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a user, you want to be certain how the data you send should be interpreted
Making base64 the default input encoding for bytes makes more sense, because it's consistent with the output.

This makes sense. I agree with your opinion.
However, Users who use Evans to fill bytes fields know the field should be inputted by quoted literals. So this behavior may cause confusion.

I think we should keep the current behavior for now, but what about breaking this behavior when releasing Evans v1.0.0?

In fact, as you said, this behavior causes a little confusion as input might be parsed as both Base64 and quoted literals so we need to clear explanation this behavior in the README or command description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the assumption right now (master branch) you need to specify a command line flag to parse as base64 (--bytes-as-base64 ) - it doesn't happen automatically.

I'm ok to wait merging this PR until we're happy changing behavior here.

We probably don't need to wait for 1.x though - a v0.x is usually expected to cause some breaking behaviour along the way. As long as we clearly document, it should be fine.

I saw there's no changelog in the repo. Should I add a paragraph mentioning the changed behavior, not just documenting the new state?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the assumption right now (master branch) you need to specify a command line flag to parse as base64 (--bytes-as-base64 ) - it doesn't happen automatically.

Ah, the behavior I assumed is a parser feature that automatically switches (fallbacks) from Base64 to quoted literals. So the --bytes-as-base64 flag will be no longer necessary.

We probably don't need to wait for 1.x though - a v0.x is usually expected to cause some breaking behaviour along the way. As long as we clearly document, it should be fine.

Yes, Semantic Versioning specifies that. However, breaking backward compatibility gives users a bad experience. Therefore, it should be avoided if possible.

I saw there's no changelog in the repo. Should I add a paragraph mentioning the changed behavior, not just documenting the new state?

Usually, I describe new features in GitHub Releases (for example, https://github.com/ktr0731/evans/releases/tag/0.10.0). It's also good to write documentation on Evans's help messages (call --help) because some users use the auto-update feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktr0731 would you agree to the following design:

  • --bytes-as-base64 selects base64 explicitly (no fallback)
  • --bytes-as-quoted-literals selects bytes as quoted literals explicitly (no fallback)
  • If neither of the two arguments are specified, try to parse as base64 first. If parsing fails, emit a warning and try parsing as literal string
  • A bigger disclaimer about base64 being the new default is added to the Readme

That way, most old literal strings should still work, because it's very rare they're also "accidentially" valid base64 too. Users get warned for a transition period, and pre-1.0 the fallback could eventually be dropped.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, for the delay. I agree with your proposed design!
I believe this design has minimal impact on existing behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! I'll try to update the PR with the proposed changes.

Fall back to bytes-as-quoted-literals mode if base64 decoding fails, and
log a warning.
Test various cases, entering base64 or quoted literals without explicitly specifying --bytes-as-base64 or --bytes-as-quoted-literals.
This test actually didn't succeed properly, but we didn't notice, as the
error wasn't propagated properly.
@flokli
Copy link
Contributor Author

flokli commented Feb 25, 2023

@ktr0731 I updated the PR. It now attempts to fall back to the old encoding in case neither --bytes-as-base64 nor --bytes-as-quoted-literals was passed explicitly, as proposed in #631 (comment).

The tests have been extended to ensure the old behaviour is preserved, base64 without explicitly specifying the parameter, and behaviour with --bytes-as-base64 or --bytes-as-quoted-literals works.

PTAL.

Copy link
Owner

@ktr0731 ktr0731 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!
Thanks for your contribution 👍

@ktr0731 ktr0731 merged commit ad18940 into ktr0731:master Feb 26, 2023
@flokli flokli deleted the bytes-base64-by-default branch February 26, 2023 11:27
@flokli
Copy link
Contributor Author

flokli commented Feb 26, 2023

Thanks! Can this be included in a release?

@ktr0731
Copy link
Owner

ktr0731 commented Feb 26, 2023

Sure. I'll create a new release soon.

@flokli
Copy link
Contributor Author

flokli commented Feb 26, 2023

Thanks!

@ktr0731
Copy link
Owner

ktr0731 commented Feb 26, 2023

Released 👉 https://github.com/ktr0731/evans/releases/tag/v0.10.11

@flokli
Copy link
Contributor Author

flokli commented Feb 26, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants