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

[screengrab] Fix escaping issue with adb path (#15981) #15986

Merged
merged 8 commits into from Feb 17, 2020

Conversation

Jeehut
Copy link
Contributor

@Jeehut Jeehut commented Feb 7, 2020

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

Fixes #15981.

Description

I've removed the escaping of the adb tool path as that added a \ in front of the path which caused the issue. There's no need for shellescaping from my understanding of the examples and documentation pages for paths, especially since this path doesn't include any whitespaces.

Testing Steps

Just make sure fastlane screengrab is still working on different platforms. I've tested macOS only.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@Jeehut
Copy link
Contributor Author

Jeehut commented Feb 7, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Feb 7, 2020
@Jeehut
Copy link
Contributor Author

Jeehut commented Feb 7, 2020

Just checked the failing tests on Circle CI and I don't think they are related to the changes I made in this PR. It was probably failing because of the timing of the tests: The tests started at the end of the 6th of February but the check was done at the beginning of the 7th of February. So, just re-running the tests will fix the CI (can't do it myself though).

Update: Just reported the failing tests as a separate issue in #15987.

Update 2: I just force-pushed to force Circle CI to re-run the tests. Should pass now!

@janpio
Copy link
Member

janpio commented Feb 8, 2020

especially since this path doesn't include any whitespaces.

How do you know that? adb can be installed in whatever location the user chooses, so the path could have a space in it, right? .shellescape is used to make this unknown string safe for usage in a shell.

I think the problem is somewhere in the handling of an env var: #15981 (comment)

Copy link
Member

@janpio janpio left a comment

Choose a reason for hiding this comment

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

Don't think this is the actual problem or a good solution.

@Jeehut
Copy link
Contributor Author

Jeehut commented Feb 8, 2020

@janpio Good point, I've updated the solution to expand the adb_path instead, to make sure we don't run into problems with paths starting with ~. Can confirm that this solved the issue as well.

@janpio
Copy link
Member

janpio commented Feb 10, 2020

Ok, my feedback made sense in theory but in practice tests are not failing as they expect the unexpanded paths. Does that make sense? Should we update the tests? Or could this have any side effects? Should not, right?

@Jeehut
Copy link
Contributor Author

Jeehut commented Feb 10, 2020

@janpio I don't think it will have any side effects, but tests will become more cumbersome and less readable since we need to change things like expect(result).to eq("./fastlane/README.md test") to be something like expect(result).to eq("#{File.expand_path('./fastlane/README.md')} test") as we can't know the path on different devices statically. That's why I personally prefer the solution from the previous commit, especially given that paths starting with . are not affected by the shellescape issue in the first place, which I just tested in irb:
Bildschirmfoto 2020-02-10 um 20 26 10

I'm reverting the last commit then, tell me if you rather prefer to update the tests instead.

But to be honest, I don't understand why expect(result).to eq("./fastlane/README.md test") is influenced by a change to the adb_path in the first place since the README file should have nothing to do with the adb_path, or am I missing something here?

@janpio
Copy link
Member

janpio commented Feb 11, 2020

That is just a bad example filename for a test that uses adb:

it "generates a valid command" do
result = Fastlane::FastFile.new.parse("lane :test do
adb(command: 'test', adb_path: './fastlane/README.md')
end").runner.execute(:test)
expect(result).to eq("./fastlane/README.md test")
end

@Jeehut
Copy link
Contributor Author

Jeehut commented Feb 11, 2020

I see, thanks for the explanation.

What is your opinion on the code of this PR? If you don't mind, we just merge it as is for the reasons explained above. It fixes the issue with the ~ and doesn't affect anything else. Checks have all passed.

@janpio
Copy link
Member

janpio commented Feb 11, 2020

I think we should undo the last commit, and then just call File.expand manually in the tests. Otherwise we have a special case in the code that we sure will forget about in a few weeks.

@Jeehut
Copy link
Contributor Author

Jeehut commented Feb 12, 2020

@janpio Okay, reverted back to the solution where we expand the adb_path at all times and made the relevant changes to the tests instead.

@janpio
Copy link
Member

janpio commented Feb 13, 2020

And we uncovered a problem on WIndows with that:

  1) Fastlane Fastlane::FastFile adb picks up path from ANDROID_HOME environment variable and handles path that has to be made safe
     Failure/Error: expect(result).to eq("#{File.expand_path(path)} test")
       expected: "C:/projects/fastlane/\"/usr/local/android-sdk/with space/platform-tools/adb\" test"
            got: "\"C:/usr/local/android-sdk/with space/platform-tools/adb\" test"
       (compared using ==)
     # ./fastlane/spec/actions_specs/adb_spec.rb:52:in `block (4 levels) in <top (required)>'

Copy link
Member

@janpio janpio left a comment

Choose a reason for hiding this comment

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

Wonderful and beautiful. Let's see if @joshdholtz agrees.

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for looking into this ❤️ Really appreciate the contribution!

@joshdholtz joshdholtz merged commit 3091bec into fastlane:master Feb 17, 2020
@fastlane-bot
Copy link

Hey @Jeehut 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a week, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀

@fastlane fastlane locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

screengrab exiting with status 127 (FastlaneCore::Interface::FastlaneShellError)
5 participants