Coder Social home page Coder Social logo

Comments (9)

jschwinger233 avatar jschwinger233 commented on May 18, 2024

其实我觉得让 grpc 接口里的 command 字段改为 []string 才是最好的, 完全不会出现任何歧义, 这是和 exec(2) 参数完全对应的.

如果保持现有的 string 类型手动切, 恐怕还要考虑 echo "a \"b" 这种引号中有转义引号的情况, 上面那段代码简单改改是不行的. 不如容我写一段没人能看懂的正则表达式.....

from core.

CMGS avatar CMGS commented on May 18, 2024

from core.

jschwinger233 avatar jschwinger233 commented on May 18, 2024

不过正则表达式也写出来了, 是这样的: [^'"\s]\S*|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"

In [26]: re.findall(r'''[^'"\s]\S*|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"''', r'''echo 'asdf asdf' 'ads' 'a\'a' "adsf" "12 1"
    ...:  "as \" sdf"''')
Out[26]: ['echo', "'asdf asdf'", "'ads'", "'a\\'a'", '"adsf"', '"12 1"', '"as \\" sdf"']

from core.

CMGS avatar CMGS commented on May 18, 2024

from core.

CMGS avatar CMGS commented on May 18, 2024

fixed in #267

from core.

warriorguo avatar warriorguo commented on May 18, 2024

我也遇到类似问题,传入command无法正常读出参数。
core版本是v21.03.15
cli版本是v21.03.01
执行lambda输出

$eru-cli lambda --pod proxy --name test --file ./testab:/bin/testab "/bin/testab -a 'show me the money' -b 'operation'"
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8] flag needs an argument: -b
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8] Usage of /bin/testab:
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]   -a string
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]   -b string
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]

直接执行binary

$./testab -a 'show me the money' -b 'operation'
a=show me the money,b=operation

testab的代码如下

package main

import (
	"flag"
	"fmt"
)

func main() {
	var (
		a, b string
	)
	flag.StringVar(&a, "a", "", "")
	flag.StringVar(&b, "b", "", "")
	flag.Parse()

	fmt.Printf("a=%s,b=%s\n", a, b)
}

from core.

chrisxuwq avatar chrisxuwq commented on May 18, 2024

我也遇到类似问题,传入command无法正常读出参数。
core版本是v21.03.15
cli版本是v21.03.01
执行lambda输出

$eru-cli lambda --pod proxy --name test --file ./testab:/bin/testab "/bin/testab -a 'show me the money' -b 'operation'"
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8] flag needs an argument: -b
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8] Usage of /bin/testab:
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]   -a string
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]   -b string
[cfdb5d301b8066956f7e546c723532796b7af1ec735fd1658e0b2fc04241d3f8]

直接执行binary

$./testab -a 'show me the money' -b 'operation'
a=show me the money,b=operation

testab的代码如下

package main

import (
	"flag"
	"fmt"
)

func main() {
	var (
		a, b string
	)
	flag.StringVar(&a, "a", "", "")
	flag.StringVar(&b, "b", "", "")
	flag.Parse()

	fmt.Printf("a=%s,b=%s\n", a, b)
}

我现在是对single word的input用strconv.Quote()来avoid的

from core.

chrisxuwq avatar chrisxuwq commented on May 18, 2024

刚刚竟然发现了个bug少点的func https://github.com/google/shlex/blob/master/shlex.go

from core.

jschwinger233 avatar jschwinger233 commented on May 18, 2024

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.