Mercurial > vim
comparison src/testdir/test_channel.vim @ 12096:0a61213afdd2 v8.0.0928
patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
commit https://github.com/vim/vim/commit/dcaa61384ca76e42f7feda5640fb85b58cee03e5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 13 17:13:09 2017 +0200
patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Problem: MS-Windows: passing arglist to job has escaping problems.
Solution: Improve escaping. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/1954)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 13 Aug 2017 17:15:03 +0200 |
parents | 2796a2c9fc17 |
children | d177c142d086 |
comparison
equal
deleted
inserted
replaced
12095:975ec6e45168 | 12096:0a61213afdd2 |
---|---|
1634 if !has('job') | 1634 if !has('job') |
1635 return | 1635 return |
1636 endif | 1636 endif |
1637 | 1637 |
1638 let g:linecount = 0 | 1638 let g:linecount = 0 |
1639 if has('win32') | 1639 let arg = 'import sys;sys.stdout.write("1\n2\n3")' |
1640 " workaround: 'shellescape' does improper escaping double quotes | |
1641 let arg = 'import sys;sys.stdout.write(\"1\n2\n3\")' | |
1642 else | |
1643 let arg = 'import sys;sys.stdout.write("1\n2\n3")' | |
1644 endif | |
1645 call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) | 1640 call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) |
1646 call WaitFor('3 <= g:linecount') | 1641 call WaitFor('3 <= g:linecount') |
1647 call assert_equal(3, g:linecount) | 1642 call assert_equal(3, g:linecount) |
1648 endfunc | 1643 endfunc |
1649 | 1644 |
1651 if !has('job') | 1646 if !has('job') |
1652 return | 1647 return |
1653 endif | 1648 endif |
1654 | 1649 |
1655 let g:linecount = 0 | 1650 let g:linecount = 0 |
1656 if has('win32') | 1651 let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")' |
1657 " workaround: 'shellescape' does improper escaping double quotes | |
1658 let arg = 'import os,sys;os.close(1);sys.stderr.write(\"test\n\")' | |
1659 else | |
1660 let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")' | |
1661 endif | |
1662 call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) | 1652 call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) |
1663 call WaitFor('1 <= g:linecount') | 1653 call WaitFor('1 <= g:linecount') |
1664 call assert_equal(1, g:linecount) | 1654 call assert_equal(1, g:linecount) |
1665 endfunc | 1655 endfunc |
1666 | 1656 |
1667 func Test_env() | 1657 func Test_env() |
1668 if !has('job') | 1658 if !has('job') |
1669 return | 1659 return |
1670 endif | 1660 endif |
1671 | 1661 |
1672 let s:envstr = '' | 1662 let g:envstr = '' |
1673 if has('win32') | 1663 if has('win32') |
1674 call job_start(['cmd', '/c', 'echo %FOO%'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'env':{'FOO': 'bar'}}) | 1664 call job_start(['cmd', '/c', 'echo %FOO%'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'env':{'FOO': 'bar'}}) |
1675 else | 1665 else |
1676 call job_start([&shell, &shellcmdflag, 'echo $FOO'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'env':{'FOO': 'bar'}}) | 1666 call job_start([&shell, &shellcmdflag, 'echo $FOO'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'env':{'FOO': 'bar'}}) |
1677 endif | 1667 endif |
1678 call WaitFor('"" != s:envstr') | 1668 call WaitFor('"" != g:envstr') |
1679 call assert_equal("bar", s:envstr) | 1669 call assert_equal("bar", g:envstr) |
1680 unlet s:envstr | 1670 unlet g:envstr |
1681 endfunc | 1671 endfunc |
1682 | 1672 |
1683 func Test_cwd() | 1673 func Test_cwd() |
1684 if !has('job') | 1674 if !has('job') |
1685 return | 1675 return |
1686 endif | 1676 endif |
1687 | 1677 |
1688 let s:envstr = '' | 1678 let g:envstr = '' |
1689 if has('win32') | 1679 if has('win32') |
1690 let expect = $TEMP | 1680 let expect = $TEMP |
1691 call job_start(['cmd', '/c', 'echo %CD%'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'cwd': expect}) | 1681 call job_start(['cmd', '/c', 'echo %CD%'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'cwd': expect}) |
1692 else | 1682 else |
1693 let expect = $HOME | 1683 let expect = $HOME |
1694 call job_start(['pwd'], {'callback': {ch,msg->execute(":let s:envstr .= msg")}, 'cwd': expect}) | 1684 call job_start(['pwd'], {'callback': {ch,msg->execute(":let g:envstr .= msg")}, 'cwd': expect}) |
1695 endif | 1685 endif |
1696 call WaitFor('"" != s:envstr') | 1686 call WaitFor('"" != g:envstr') |
1697 let expect = substitute(expect, '[/\\]$', '', '') | 1687 let expect = substitute(expect, '[/\\]$', '', '') |
1698 let s:envstr = substitute(s:envstr, '[/\\]$', '', '') | 1688 let g:envstr = substitute(g:envstr, '[/\\]$', '', '') |
1699 if $CI != '' && stridx(s:envstr, '/private/') == 0 | 1689 if $CI != '' && stridx(g:envstr, '/private/') == 0 |
1700 let s:envstr = s:envstr[8:] | 1690 let g:envstr = g:envstr[8:] |
1701 endif | 1691 endif |
1702 call assert_equal(expect, s:envstr) | 1692 call assert_equal(expect, g:envstr) |
1703 unlet s:envstr | 1693 unlet g:envstr |
1704 endfunc | 1694 endfunc |
1705 | 1695 |
1706 function Ch_test_close_lambda(port) | 1696 function Ch_test_close_lambda(port) |
1707 let handle = ch_open('localhost:' . a:port, s:chopt) | 1697 let handle = ch_open('localhost:' . a:port, s:chopt) |
1708 if ch_status(handle) == "fail" | 1698 if ch_status(handle) == "fail" |
1719 | 1709 |
1720 func Test_close_lambda() | 1710 func Test_close_lambda() |
1721 call ch_log('Test_close_lambda()') | 1711 call ch_log('Test_close_lambda()') |
1722 call s:run_server('Ch_test_close_lambda') | 1712 call s:run_server('Ch_test_close_lambda') |
1723 endfunc | 1713 endfunc |
1714 | |
1715 func s:test_list_args(cmd, out, remove_lf) | |
1716 try | |
1717 let g:out = '' | |
1718 call job_start([s:python, '-c', a:cmd], {'callback': {ch, msg -> execute('let g:out .= msg')}, 'out_mode': 'raw'}) | |
1719 call WaitFor('"" != g:out') | |
1720 if has('win32') | |
1721 let g:out = substitute(g:out, '\r', '', 'g') | |
1722 endif | |
1723 if a:remove_lf | |
1724 let g:out = substitute(g:out, '\n$', '', 'g') | |
1725 endif | |
1726 call assert_equal(a:out, g:out) | |
1727 finally | |
1728 unlet g:out | |
1729 endtry | |
1730 endfunc | |
1731 | |
1732 func Test_list_args() | |
1733 if !has('job') | |
1734 return | |
1735 endif | |
1736 | |
1737 call s:test_list_args('import sys;sys.stdout.write("hello world")', "hello world", 0) | |
1738 call s:test_list_args('import sys;sys.stdout.write("hello\nworld")', "hello\nworld", 0) | |
1739 call s:test_list_args('import sys;sys.stdout.write(''hello\nworld'')', "hello\nworld", 0) | |
1740 call s:test_list_args('import sys;sys.stdout.write(''hello"world'')', "hello\"world", 0) | |
1741 call s:test_list_args('import sys;sys.stdout.write(''hello^world'')', "hello^world", 0) | |
1742 call s:test_list_args('import sys;sys.stdout.write("hello&&world")', "hello&&world", 0) | |
1743 call s:test_list_args('import sys;sys.stdout.write(''hello\\world'')', "hello\\world", 0) | |
1744 call s:test_list_args('import sys;sys.stdout.write(''hello\\\\world'')', "hello\\\\world", 0) | |
1745 call s:test_list_args('import sys;sys.stdout.write("hello\"world\"")', 'hello"world"', 0) | |
1746 call s:test_list_args('import sys;sys.stdout.write("h\"ello worl\"d")', 'h"ello worl"d', 0) | |
1747 call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo wor\\\"l\"d")', 'h"e\"llo wor\"l"d', 0) | |
1748 call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo world")', 'h"e\"llo world', 0) | |
1749 call s:test_list_args('import sys;sys.stdout.write("hello\tworld")', "hello\tworld", 0) | |
1750 | |
1751 " tests which not contain spaces in the argument | |
1752 call s:test_list_args('print("hello\nworld")', "hello\nworld", 1) | |
1753 call s:test_list_args('print(''hello\nworld'')', "hello\nworld", 1) | |
1754 call s:test_list_args('print(''hello"world'')', "hello\"world", 1) | |
1755 call s:test_list_args('print(''hello^world'')', "hello^world", 1) | |
1756 call s:test_list_args('print("hello&&world")', "hello&&world", 1) | |
1757 call s:test_list_args('print(''hello\\world'')', "hello\\world", 1) | |
1758 call s:test_list_args('print(''hello\\\\world'')', "hello\\\\world", 1) | |
1759 call s:test_list_args('print("hello\"world\"")', 'hello"world"', 1) | |
1760 call s:test_list_args('print("hello\tworld")', "hello\tworld", 1) | |
1761 endfunc |