Skip to content

Encode logfile option with URLEncoder #1363

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

Merged
merged 2 commits into from
Jun 1, 2021
Merged

Conversation

jasonxh
Copy link
Contributor

@jasonxh jasonxh commented May 30, 2021

References #786

Issue

Currently, applying the gradle plugin to a subproject will fail gradle build from root project dir, due to a mismatch in the expectation of where the logfile is located. The gradle plugin calculates a relative path to the subproject, while the protoc codegen plugin evaluates it as relative to the current working dir (which is root dir).

Background

There had been several back-and-forths regarding how to pass the logfile option in the past, ranging from one-off character substitution, to relative paths, to absolute paths (see #674 and #787). The root of the problem is that protoc codegen plugin options are passed in as a single string, encoded in a special format like this:

--akkaGrpc_out=<key1>=<value1>,<key2>=<value2>:<out_dir>

It's easy to see how several characters play a special role in this encoding, and thus should not appear in keys or values: [=,:].

This problem was originally surfaced as a Windows-only problem, where absolute file paths include C:\ (see #669). However, it doesn't actually matter if we are passing logfile as absolute or relative, since those special characters mentioned above can creep in either way. Granted, no sane person would name their files like that, but it's possible.

Proposed fix

Encode logfile with URLEncoder when composing options, and decode it with URLDecoder inside the protoc codegen plugin. This is a well-known encoding scheme that allows only [a-zA-Z0-9.-*_+%] in the encoded output. Note that none of the special characters mentioned above are allowed here.

I also renamed the option to logfile_enc to make it an explicit breaking change, in case the codegen plugin is being used in other context. But I don't feel strongly about this, so feel free to suggest otherwise.

Testing

Verified to fix #786 on my Mac. Would be great if someone can help test this on a Windows machine.

@lightbend-cla-validator

Hi @jasonxh,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement:

https://www.lightbend.com/contribute/cla

@akka-ci
Copy link

akka-ci commented May 30, 2021

Thank you for your pull request! After a quick sanity check one of the team will reply with 'OK ΤO ΤESΤ' to kick off our automated validation on Jenkins. This compiles the project, runs the tests, and checks for things like binary compatibility and source code formatting. When two team members have also manually reviewed and (perhaps after asking for some amendments) accepted your contribution, it should be good to be merged.

For more details about our contributing process, check out CONTRIBUTING.md - and feel free to ask!

@raboof
Copy link
Contributor

raboof commented May 30, 2021

OK TO TEST

@raboof
Copy link
Contributor

raboof commented May 30, 2021

@hithran @orendain @eshepelyuk thoughts?

@eshepelyuk
Copy link
Contributor

@hithran @orendain @eshepelyuk thoughts?
looks ok to me.

@@ -45,7 +46,8 @@ object Main extends App {
private val extraGenerators: List[String] =
parameters.getOrElse("extra_generators", "").split(";").toList.filter(_ != "")

private val logger = parameters.get("logfile").map(new FileLogger(_)).getOrElse(SilencedLogger)
private val logger: Logger =
parameters.get("logfile_enc").map(URLDecoder.decode(_, "utf-8")).map(new FileLogger(_)).getOrElse(SilencedLogger)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we fall back to the logfile parameter when logfile_enc is not present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added fallback logic

Copy link
Contributor

@raboof raboof left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@raboof raboof merged commit d896f57 into akka:master Jun 1, 2021
@jasonxh jasonxh deleted the logfile_enc branch June 5, 2021 22:10
@hithran
Copy link
Contributor

hithran commented Jun 8, 2021

@hithran @orendain @eshepelyuk thoughts?

@jasonxh Great solution! Thanks!

@upgle upgle mentioned this pull request Jul 12, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log file can not be found for multiproject Gradle projects
6 participants