This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 189119 - Escaping of metacharacters in property names & values in action mappings
Summary: Escaping of metacharacters in property names & values in action mappings
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Assignee: Milos Kleint
URL:
Keywords:
: 202759 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-08-02 08:11 UTC by pekarna
Modified: 2012-04-26 11:18 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pekarna 2010-08-02 08:11:27 UTC
STR:

A)

1) Create a maven project from a quickstart (to have a test file),
2) Project properties -> Actions -> Test File -> Set Properties:
      workingDirectory=C:\
3) Open the test file and run IDE's "Test file" action
4) Maven build will fail with an error which is probably caused by unescaped \ or such.

B)

Same as above, except in 2) set  workingDirectory="C:\"

Maven build will fail with an error which seems like the " is not escaped, thus the mvn command ends in the middle.

NetBeans: Executing 'C:\sw\Java\apache-maven-2.2.0\bin\mvn.bat -Dprofile=ondra-comp-test -DworkingDirectory=\"C:\\" -Dtest=FakturaceRequestProcessorTest -Dnetbeans.execution=true test-compile surefire:test'
...
------------------------------------------------------------------------
[ERROR]BUILD FAILURE
------------------------------------------------------------------------
You must specify at least one goal or lifecycle phase to perform build steps.
Comment 1 Jesse Glick 2011-03-07 16:45:30 UTC
http://jira.codehaus.org/browse/MNG-5035 makes it hard to test on Linux. Works for me in 7.0 on XP (using Maven 3.0). For a main class, I set working dir to C:\ and a program

        System.out.println( System.getProperty("user.dir") );
        System.out.println(Arrays.toString(new File(System.getProperty("user.dir")).listFiles()));

prints

C:\
[C:\AUTOEXEC.BAT, ...]

as expected. For tests, you cannot set the CWD from the command line; see bug #189117. With the snippet listed there in the POM, I get

C:\DOCUME~1\JESSEG~1\LOCALS~1\Temp
[C:\DOCUME~1\JESSEG~1\LOCALS~1\Temp\....]

as expected. Anyway if you want to use a backslash in an action property you need to escape it: something=c:\\some\\dir
Comment 2 pekarna 2011-03-24 02:34:51 UTC
Ok, it's caused by not escaping.

Could the escaping be mentioned in the hint pane at the bottom of the window?
(Reopening for this purpose.)

Also, I wonder where is a docs for what everything can be used in that window.
E.g. "Test file" has test=${packageClassName}
That seems like some NetBeans-specific value.
Is there some list of what _everything_ is being replaced?
Comment 3 Jesse Glick 2011-03-24 17:19:57 UTC
I am not the original author so I cannot be sure, but I think there is no such document. Could probably include a summary of special properties. At least some are already offered in the special button to the left of the pane.
Comment 4 Jesse Glick 2011-09-28 16:39:14 UTC
*** Bug 202759 has been marked as a duplicate of this bug. ***
Comment 5 athompson 2011-09-28 22:41:08 UTC
Also XML characters like "<" need to be escaped.
Comment 6 athompson 2011-09-28 23:01:27 UTC
My two cents is that Netbeans should escape everything in the box as necessary, not the user.  NB will have to escape for storing in nbactions.xml anyway since the user shouldn't be expected to remember  to escape XML characters just because NB needs it.  What is specified to the right of the "=" should be verbatim the value of the property, including quotes, backslashes, and even leading spaces.  These properties are in turn often injected into properties files, and things get too confusing and error prone when you have to do nested layers of escaping.  Besides, that's yet another thing for the user to keep track of.
Comment 7 Jesse Glick 2011-10-19 18:43:34 UTC
(In reply to comment #6)
> What is specified to the right of the "=" should be
> verbatim the value of the property, including quotes, backslashes,
> and even leading spaces

Debatable about the latter two; when the list of properties is presented in a textarea, one possible interpretation is as a java.util.Properties, which requires \ to be escaped as \\ and ignores unescaped leading spaces in values (but does permit = to be present in a key when escaped). Compare the Ant option panel (which is a bit clearer by using the text/x-properties editor kit). A less ambiguous UI might use a JTable or similar to let you add key/value pairs as raw text, though this might make it awkward to insert newlines (*).

As to use of '<', I am not sure this is even possible in key names using the current nbactions.xml format, which uses <key>value</key> syntax; while XML permits most (not all!) characters in text nodes when properly escaped, the same is not true of element names. (See bug #200901 for a similar issue unrelated to action mappings.) Fixing that would require a different persisted format for action mappings, which introduces compatibility and upgrade issues. And of course the Maven CLI parser by its nature cannot handle property names containing '='. But perhaps you were referring only to values.

(*) Assuming the Maven launcher can actually handle such exotic characters. The Unix launcher uses "$@" which implies that it should be safe. No clue how the Windows batch script deals with metachars.
Comment 8 athompson 2011-10-20 19:21:44 UTC
Yup, I was thinking about just the values.  It's reasonable (and expected by most) to have restrictions on property names.

As far as the values are concerned, I'm a big fan of adding them in a way that you don't have to worry about escaping them (for netbeans) so you don't have to worry about nested escaping (for example, a SQL Server JDBC URL that becomes "jdbc:sqlserver://qa-db\\\\dbqa;databaseName=prototype",  note the 1 backslash becomes 4, and that's the simplest case).  But I can live with that so long as it works.
Comment 9 athompson 2011-10-20 19:34:22 UTC
Actually, if the Netbeans "Properties" text area matched the format used in the Jenkins text area so you could just copy/paste between the two, that would be a huge timesaver.  So how about using the same escaping for properties as Jenkins?
Comment 10 athompson 2011-10-26 21:04:14 UTC
I need to bump up the priority because there are two big problems.  First, the text area where you set the properties is not..."idempotent".  That is, if you add a set of properties including "text=foo\\\\bar", it will be remembered as "text=foo\\bar".  The next time you edit a properties the "text" property will be remembered as "text=foo\bar", and so on.  I imagine this can be fixed by re-escaping the properties before putting them in the text area.  The other major problem is that trying to add a property with a blank string as a value the form "emptyString=" doesn't work; the "emptyString" property isn't saved and the only way add it is to modify the xml file directly.
Comment 11 athompson 2011-10-26 21:05:55 UTC
Please forget what I said about making it look like Jenkins.  I just looked at it again.  :)
Comment 12 Jesse Glick 2011-10-27 21:49:16 UTC
Not P2 when there is a straightforward workaround: edit nbactions.xml directly.
Comment 13 Milos Kleint 2012-04-04 06:32:07 UTC
(In reply to comment #10)
>  The other
> major problem is that trying to add a property with a blank string as a value
> the form "emptyString=" doesn't work; the "emptyString" property isn't saved
> and the only way add it is to modify the xml file directly.

this has been fixed recently as part of issue 205214
Comment 14 Milos Kleint 2012-04-25 10:32:54 UTC
(In reply to comment #2)
> 
> Also, I wonder where is a docs for what everything can be used in that window.
> E.g. "Test file" has test=${packageClassName}
> That seems like some NetBeans-specific value.
> Is there some list of what _everything_ is being replaced?

fixed lately by including a list of expressions related to current selection into the Add> button popup menu.
Comment 15 Milos Kleint 2012-04-25 11:31:06 UTC
(In reply to comment #10)
> I need to bump up the priority because there are two big problems.  First, the
> text area where you set the properties is not..."idempotent".  That is, if you
> add a set of properties including "text=foo\\\\bar", it will be remembered as
> "text=foo\\bar".  The next time you edit a properties the "text" property will
> be remembered as "text=foo\bar", and so on.  I imagine this can be fixed by
> re-escaping the properties before putting them in the text area.  The other
> major problem is that trying to add a property with a blank string as a value
> the form "emptyString=" doesn't work; the "emptyString" property isn't saved
> and the only way add it is to modify the xml file directly.

fixed in http://hg.netbeans.org/core-main/rev/20fa0ec1ae47
Comment 16 Quality Engineering 2012-04-26 10:33:42 UTC
Integrated into 'main-golden', will be available in build *201204260400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/20fa0ec1ae47
User: Milos Kleint <mkleint@netbeans.org>
Log: #189119 stop eating up backslashes
Comment 17 Milos Kleint 2012-04-26 11:16:30 UTC
(In reply to comment #0)
> STR:
> 
> A)
> 
> 1) Create a maven project from a quickstart (to have a test file),
> 2) Project properties -> Actions -> Test File -> Set Properties:
>       workingDirectory=C:\
> 3) Open the test file and run IDE's "Test file" action
> 4) Maven build will fail with an error which is probably caused by unescaped \
> or such.
> 

workingDirectory property does nothing within the context of surefire plugin. The definion of the plugin parameter doesn't allow for property passed from cmd line to modify it.. see http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#workingDirectory

in latest dev build I can reproduce what jglick did with exec:exec plugin configuration, the property is named exec.workingdir then. Escaping the backclashes is no longer necessary. Now the content will be written to file as is, so C:\ should be sufficient.
Comment 18 Milos Kleint 2012-04-26 11:18:15 UTC
consider fixed, if I missed any of the problems mentioned in the issue, please submit a separate issue, this one is already too long and fragmented. Thank you.