Commit 279b806 1 parent 6ba49e2 commit 279b806 Copy full SHA for 279b806
File tree 3 files changed +20
-4
lines changed
3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package expand
6
6
import (
7
7
"fmt"
8
8
"strconv"
9
+ "strings"
9
10
10
11
"mvdan.cc/sh/v3/syntax"
11
12
)
@@ -105,9 +106,9 @@ func oneIf(b bool) int {
105
106
return 0
106
107
}
107
108
108
- // atoi is just a shorthand for strconv.Atoi that ignores the error,
109
- // just like shells do.
109
+ // atoi is like strconv.Atoi, but it ignores errors and trims whitespace.
110
110
func atoi (s string ) int {
111
+ s = strings .TrimSpace (s )
111
112
n , _ := strconv .Atoi (s )
112
113
return n
113
114
}
Original file line number Diff line number Diff line change @@ -32,16 +32,18 @@ func isBuiltin(name string) bool {
32
32
return false
33
33
}
34
34
35
+ // TODO: oneIf and atoi are duplicated in the expand package.
36
+
35
37
func oneIf (b bool ) int {
36
38
if b {
37
39
return 1
38
40
}
39
41
return 0
40
42
}
41
43
42
- // atoi is just a shorthand for strconv.Atoi that ignores the error,
43
- // just like shells do.
44
+ // atoi is like strconv.Atoi, but it ignores errors and trims whitespace.
44
45
func atoi (s string ) int {
46
+ s = strings .TrimSpace (s )
45
47
n , _ := strconv .Atoi (s )
46
48
return n
47
49
}
Original file line number Diff line number Diff line change @@ -1412,6 +1412,10 @@ var runTests = []runTest{
1412
1412
"[[ 3 -lt 4 ]]" ,
1413
1413
"" ,
1414
1414
},
1415
+ {
1416
+ "[[ ' 3' -lt '4 ' ]]" ,
1417
+ "" ,
1418
+ },
1415
1419
{
1416
1420
"[[ 3 -gt 4 ]]" ,
1417
1421
"exit status 1" ,
@@ -1637,6 +1641,7 @@ var runTests = []runTest{
1637
1641
{"[ 0 -gt 1 -o 1 -gt 0 ]" , "" },
1638
1642
{"[ 3 -gt 4 ]" , "exit status 1" },
1639
1643
{"[ 3 -lt 4 ]" , "" },
1644
+ {"[ ' 3' -lt '4 ' ]" , "" },
1640
1645
{
1641
1646
"[ -e a ] && echo x; >a; [ -e a ] && echo y" ,
1642
1647
"y\n " ,
@@ -1826,6 +1831,14 @@ var runTests = []runTest{
1826
1831
"let x=3; let 3%0; ((3%0)); echo $((x%y)); let x%=0" ,
1827
1832
"division by zero\n division by zero\n division by zero\n division by zero\n exit status 1 #JUSTERR" ,
1828
1833
},
1834
+ {
1835
+ "let x=' 3'; echo $x" ,
1836
+ "3\n " ,
1837
+ },
1838
+ {
1839
+ "x=' 3'; let x++; echo \" $x\" " ,
1840
+ "4\n " ,
1841
+ },
1829
1842
1830
1843
// set/shift
1831
1844
{
You can’t perform that action at this time.
0 commit comments