|
From: <otm...@us...> - 2010-06-15 06:34:22
|
Revision: 7065
http://jython.svn.sourceforge.net/jython/?rev=7065&view=rev
Author: otmarhumbel
Date: 2010-06-15 06:34:16 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
handle arguments containing % signs
partly fixes issue #1599
Modified Paths:
--------------
trunk/jython/Lib/test/test_bat_jy.py
trunk/jython/src/shell/jython.bat
Modified: trunk/jython/Lib/test/test_bat_jy.py
===================================================================
--- trunk/jython/Lib/test/test_bat_jy.py 2010-06-15 06:33:20 UTC (rev 7064)
+++ trunk/jython/Lib/test/test_bat_jy.py 2010-06-15 06:34:16 UTC (rev 7065)
@@ -102,7 +102,7 @@
stdoutMonitor.start()
stderrMonitor.start()
while self.isAlive(process):
- Thread.sleep(500)
+ Thread.sleep(300)
return self.getOutput(outfilePath)
finally:
os.remove(starterPath)
@@ -158,6 +158,7 @@
jythonArgs += flag
else:
jythonArgs = flag
+ jythonArgs = jythonArgs.replace('%%', '%') # workaround two .bat files
args.append(flag)
process = StarterProcess()
out = process.run(args, javaHome, jythonHome, jythonOpts)
@@ -267,11 +268,19 @@
self.assertOutput(['-J-DmyProperty=myValue'])
def test_property_singlequote(self):
- self.assertOutput(["-J-DmyProperty='myValue'"]) # a space inside value does not work in jython.bat
+ self.assertOutput(["-J-DmyProperty='myValue'"])
+ # a space inside value does not work in jython.bat
+ def __test_property_singlequote_space(self):
+ self.assertOutput(["-J-DmyProperty='my Value'"])
+
def test_property_doublequote(self):
- self.assertOutput(['-J-DmyProperty="myValue"']) # a space inside value does not work in jython.bat
+ self.assertOutput(['-J-DmyProperty="myValue"'])
+ # a space inside value does not work in jython.bat
+ def __test_property_doublequote_space(self):
+ self.assertOutput(['-J-DmyProperty="my Value"'])
+
def test_property_underscore(self):
self.assertOutput(['-J-Dmy_Property=my_Value'])
@@ -338,6 +347,36 @@
def test_star_existing_singlequoted(self):
self.assertOutput(['-c', 'import sys; print sys.argv[1:]', "'*.bat'", "'*.bat'"])
+class ArgsSpacesTest(BaseTest):
+ def test_doublequoted(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', '"part1 part2"', '2nd'])
+
+ def test_singlequoted(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', "'part1 part2'", '2nd'])
+
+ # this test currently fails
+ def __test_unbalanced_doublequote(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', 'Scarlet O"Hara', '2nd'])
+
+ def test_unbalanced_singlequote(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', "Scarlet O'Hara", '2nd'])
+
+class ArgsSpecialCharsTest(BaseTest):
+ # exclamation marks are still very special ...
+ def __test_exclamationmark(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', 'foo!', 'ba!r', '!baz', '!'])
+
+ # because we go through a starter.bat file, we have to simulate % with %%
+ def test_percentsign(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', 'foo%%1', '%%1bar', '%%1', '%%'])
+
+ def test_colon(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', 'foo:', ':bar'])
+
+ # a semicolon at the beginning of an arg currently fails (e.g. ;bar)
+ def test_semicolon(self):
+ self.assertOutput(['-c', 'import sys; print sys.argv[1:]', 'foo;'])
+
class DummyTest(unittest.TestCase):
def test_nothing(self):
pass
@@ -351,7 +390,9 @@
JavaOptsTest,
ArgsTest,
DoubleDashTest,
- GlobPatternTest)
+ GlobPatternTest,
+ ArgsSpacesTest,
+ ArgsSpecialCharsTest)
else:
# provide at least one test for the other platforms - happier build bots
test_support.run_unittest(DummyTest)
Modified: trunk/jython/src/shell/jython.bat
===================================================================
--- trunk/jython/src/shell/jython.bat 2010-06-15 06:33:20 UTC (rev 7064)
+++ trunk/jython/src/shell/jython.bat 2010-06-15 06:34:16 UTC (rev 7065)
@@ -18,6 +18,8 @@
goto finish
:normalstart
+set _PERCENT=%%
+set _EXCLAMATION=!
setlocal enabledelayedexpansion
rem ----- Verify and set required environment variables -----------------------
@@ -25,21 +27,21 @@
set _JAVA_CMD=java
rem remove surrounding quotes from java home, to be able to safely empty-test it
set _TRIMMED_JAVA_HOME=%JAVA_HOME%
-for /f "useback tokens=*" %%a in ('%_TRIMMED_JAVA_HOME%') do set _TRIMMED_JAVA_HOME=%%~a
+for /f "usebackq tokens=*" %%a in ('%_TRIMMED_JAVA_HOME%') do set _TRIMMED_JAVA_HOME=%%~a
if not "%_TRIMMED_JAVA_HOME%"=="" (
set _JAVA_CMD="%JAVA_HOME:"=%\bin\java"
)
rem remove surrounding quotes from jython opts, to be able to safely empty-test it
set _TRIMMED_JYTHON_OPTS=%JYTHON_OPTS%
-for /f "useback tokens=*" %%a in ('%_TRIMMED_JYTHON_OPTS%') do set _TRIMMED_JYTHON_OPTS=%%~a
+for /f "usebackq tokens=*" %%a in ('%_TRIMMED_JYTHON_OPTS%') do set _TRIMMED_JYTHON_OPTS=%%~a
if not "%_TRIMMED_JYTHON_OPTS%"=="" (
set _JYTHON_OPTS="%_TRIMMED_JYTHON_OPTS%"
)
rem remove surrounding quotes from jython home, to be able to safely empty-test it
set _TRIMMED_JYTHON_HOME=%JYTHON_HOME%
-for /f "useback tokens=*" %%a in ('%_TRIMMED_JYTHON_HOME%') do set _TRIMMED_JYTHON_HOME=%%~a
+for /f "usebackq tokens=*" %%a in ('%_TRIMMED_JYTHON_HOME%') do set _TRIMMED_JYTHON_HOME=%%~a
if not "%_TRIMMED_JYTHON_HOME%"=="" (
set _JYTHON_HOME="%_TRIMMED_JYTHON_HOME%"
goto gotHome
@@ -95,6 +97,10 @@
set _ARGS=%_ARGS:_=_U%
set _ARGS=%_ARGS:'=_S%
set _ARGS=%_ARGS:"=_D%
+rem also escape % signs
+set _replaceVal=%_ARGS%
+call :escape
+set _ARGS=%_replaceVal%
set _ARGS="%_ARGS%"
set _JYTHON_ARGS=
@@ -140,7 +146,10 @@
goto :nextArg
)
-rem now unescape _D, _S and _U
+rem now unescape everything
+set _replaceVal=%_CMP%
+call :escape
+set _CMP=%_replaceVal%
set _CMP=%_CMP:_D="%
set _CMP=%_CMP:_S='%
set _CMP=%_CMP:_U=_%
@@ -210,6 +219,80 @@
set _TRIMMED_JAVA_HOME=
set _TRIMMED_JYTHON_HOME=
set _TRIMMED_JYTHON_OPTS=
+goto finish
+
+
+REM escapes or unescapes % with @@P@@, and ! with @@E@@
+REM input: a text variable named _replaceVal
+REM result: _replaceVal has the new value
+:escape
+if not defined _replaceVal goto :EOF
+set /a _index=-1
+set _replaced=
+
+:escapeNext
+set /a _index=%_index% + 1
+call set _escapeChar=%%_replaceVal:~%_index%,1%%
+if ^"==^%_escapeChar% goto noEscape
+if ''=='%_escapeChar%' goto escapeEnd
+if "%_escapeChar%"==" " goto noEscape
+if "%_escapeChar%"=="@" goto unescapeCheck
+if "%_escapeChar%"=="%_EXCLAMATION%" goto escapeExclamation
+if "%_escapeChar%"=="%_PERCENT%" goto escapePercent
+:noEscape
+set _replaced=%_replaced%%_escapeChar%
+goto escapeNext
+
+:escapeExclamation
+set _replaced=%_replaced%@@E@@
+goto escapeNext
+
+:escapePercent
+set _replaced=%_replaced%@@P@@
+goto escapeNext
+
+:unescapeCheck
+set _isExclamation=
+set _isPercent=
+set _isUnrecognized=true
+set /a _aheadIndex=%_index% + 1
+call set _aheadChar=%%_replaceVal:~%_aheadIndex%,1%%
+if ^"==^%_aheadChar% goto noEscape
+if "%_aheadChar%"=="@" set /a _aheadIndex=%_aheadIndex% + 1
+call set _aheadChar=%%_replaceVal:~%_aheadIndex%,1%%
+if ^"==^%_aheadChar% goto noEscape
+if "%_aheadChar%"=="E" set _isExclamation=true & set _isUnrecognized=
+if "%_aheadChar%"=="P" set _isPercent=true & set _isUnrecognized=
+if defined _isUnrecognized goto noEscape
+set _isUnrecognized=true
+set /a _aheadIndex=%_aheadIndex% + 1
+call set _aheadChar=%%_replaceVal:~%_aheadIndex%,1%%
+if ^"==^%_aheadChar% goto noEscape
+if "%_aheadChar%"=="@" set /a _aheadIndex=%_aheadIndex% + 1
+call set _aheadChar=%%_replaceVal:~%_aheadIndex%,1%%
+if ^"==^%_aheadChar% goto noEscape
+if "%_aheadChar%"=="@" set _isUnrecognized=
+if defined _isUnrecognized goto noEscape
+if defined _isExclamation goto unescapeExclamation
+if defined _isPercent goto unescapePercent
+goto noEscape
+
+:unescapeExclamation
+set _replaced=%_replaced%%_EXCLAMATION%
+set /a _index=%_index% + 4
+goto escapeNext
+
+:unescapePercent
+set _replaced=%_replaced%%_PERCENT%
+set /a _index=%_index% + 4
+goto escapeNext
+
+:escapeEnd
+set _replaceVal=%_replaced%
+goto :EOF
+
+
+
:finish
%COMSPEC% /c exit /b %E%
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|