MavenHelper icon indicating copy to clipboard operation
MavenHelper copied to clipboard

Not passing quotation marks to the terminal

Open mateusz-bajorek opened this issue 2 years ago • 2 comments

Describe the bug When invoking a self-created goal, the quotation marks are not passed to the terminal.

To Reproduce Steps to reproduce the behavior:

  1. Create a goal like clean package "-Dproject.build.sourceEncoding=UTF-8" "-Duser.language=en" "-Duser.region=US" "-Duser.timezone=UTC"
  2. Run the goal
  3. See an error on Windows (PowerShell requires parameters with . characters to be wrapped in quotation marks - check the screenshot to see how is the command "divided" when there are no quotation marks present)

Expected behavior The goal content should be passed to the terminal as is.

Screenshots idea64_2022-08-15_09-53-33 idea64_2022-08-15_09-54-54

Environment : IntelliJ IDEA 2022.2 (Ultimate Edition) Build #IU-222.3345.118, built on July 26, 2022 Licensed to Mateusz Bajorek Subscription is active until August 10, 2023. Runtime version: 17.0.3+7-b469.32 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 4 Registry: analyze.exceptions.on.the.fly=true documentation.show.toolbar=true ide.tooltip.initialDelay=602 ide.balloon.shadow.size=0

Non-Bundled Plugins: some.awesome (1.14) org.sylfra.idea.plugins.linessorter (1.0.1) org.jetbrains.plugins.go-template (222.3345.108) org.intellij.plugins.hcl (222.3345.108) name.kropp.intellij.makefile (222.3345.108) lermitage.intellij.extratci (1.23.0.201) lermitage.intellij.extra.icons (2022.1.8) krasa.CpuUsageIndicator (1.14) indent-rainbow.indent-rainbow (2.0.2) com.ultrahob.zerolength.plugin (0.95) com.shetline.ligatures-limited (1.0.4) com.nasller.CodeGlancePro (1.4.8) com.jetbrains.plugins.ini4idea (222.3345.144) com.intellij.plugin.adernov.powershell (2.0.10) com.jetbrains.jax.ws (222.3345.118) com.intellij.guice (222.3345.118) com.andrey4623.rainbowcsv (2.0.2) awesome.console (0.1337.12) YAML/Ansible support (0.11.2) String Manipulation (9.5.1) org.sonarlint.idea (7.0.0.52289) mobi.hsz.idea.gitignore (4.4.2) gr.jchrist.gitextender (0.7.0) zielu.gittoolbox (212.9.7) git-extended-update-index (0.1.2) com.github.lppedd.idea-return-highlighter (0.8.2) com.dmarcotte.handlebars (222.3345.108) ir.msdehghan.plugins.ansible (0.92) com.intellij.lang.puppet (222.3345.108) com.intellij.kubernetes (222.3345.108) Batch Scripts Support (1.0.13) ru.adelf.idea.dotenv (2022.2) org.apache.camel (0.8.13) dev.eltonsandre.intellij.spring.assistant.plugin (2022.2.2) com.yiycf.plugins.mavenDependencyHelper (2.5) com.haulmont.jpab (2022.3.4-222) MavenRunHelper (4.21.222.2964.0) izhangzhihao.rainbow.brackets (6.25) cn.yiiguxing.plugin.translate (3.3.4)

Kotlin: 222-1.7.10-release-334-IJ3345.118

mateusz-bajorek avatar Aug 15 '22 07:08 mateusz-bajorek

I've debugged this a bit and it looks like Goal#parse removes the quotation marks from the command. It's done by the CommandLineTokenizer, however, if I try and escape the quotation marks like clean package \"-Dproject.build.sourceEncoding=UTF-8\" it is passed to the console just like that. So currently:

  • clean package "-Dproject.build.sourceEncoding=UTF-8" produces clean package -Dproject.build.sourceEncoding=UTF-8 in the terminal
  • clean package \"-Dproject.build.sourceEncoding=UTF-8\" produces clean package \"-Dproject.build.sourceEncoding=UTF-8\" in the terminal

Even if the call is modified and the goals list contains un-escaped quoted parameter in the end, the ParametersListUtil#escape adds the escape backslashes again when being called in the stack by MavenRunnerParameters#getCommandLine from ProgramRunnerUtils#executeInTerminal.

All in all, I believe the GoalEditor should validate the input, either converting double-quotes to single quotes (i.e. to clean package '-Dproject.build.sourceEncoding=UTF-8' - this is a valid command from the PowerShell point of view) or at least display a warning if the cmdPanel contains double-quotes - just so that others don't go down the rabbit hole I did :)

mateusz-bajorek avatar Aug 15 '22 10:08 mateusz-bajorek

relates to #85

krasa avatar Oct 13 '22 12:10 krasa