You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/27 02:52:20 UTC

[incubator-eventmesh] branch master updated: modify jqer default wrap left character

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new a539bab3 modify jqer default wrap left character
     new 3a188567 Merge pull request #1939 from walterlife/optimize-jqer-logic
a539bab3 is described below

commit a539bab3933b7f49c8b80f36b967b7af228865d6
Author: yuweizhu <yu...@tencent.com>
AuthorDate: Wed Oct 26 23:31:38 2022 +0800

    modify jqer default wrap left character
---
 eventmesh-workflow-go/third_party/jqer/jqer.go | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/eventmesh-workflow-go/third_party/jqer/jqer.go b/eventmesh-workflow-go/third_party/jqer/jqer.go
index 80737091..b3932c68 100644
--- a/eventmesh-workflow-go/third_party/jqer/jqer.go
+++ b/eventmesh-workflow-go/third_party/jqer/jqer.go
@@ -30,6 +30,8 @@ import (
 
 const (
 	defaultWrapBeginCharacter                 = "$"
+	defaultWrapLeftCharacter                  = "{"
+	defaultWrapRightCharacter                 = "}"
 	jqStartToken              lexer.TokenType = iota
 	stringToken
 	errorToken
@@ -76,10 +78,10 @@ func NewJQ(options ...Option) JQ {
 		jq.options.WrapBegin = defaultWrapBeginCharacter
 	}
 	if len(jq.options.WrapLeftSeparator) == 0 {
-		jq.options.WrapLeftSeparator = defaultWrapBeginCharacter
+		jq.options.WrapLeftSeparator = defaultWrapLeftCharacter
 	}
 	if len(jq.options.WrapRightSeparator) == 0 {
-		jq.options.WrapRightSeparator = defaultWrapBeginCharacter
+		jq.options.WrapRightSeparator = defaultWrapRightCharacter
 	}
 	return jq
 }
@@ -92,7 +94,7 @@ func (j *jqer) One(input interface{}, command interface{}) (interface{}, error)
 	}
 
 	if len(output) != 1 {
-		return nil, NewError(ErrCodeJQNotObject, "the `jq` or `js` command produced multiple outputs")
+		return nil, NewError(ErrCodeJQNotObject, "command produced multiple outputs")
 	}
 
 	return output[0], nil
@@ -186,7 +188,7 @@ func (j *jqer) jqState(l *lexer.L) lexer.StateFunc {
 		}
 		src[i] = string(r)
 
-		if src[i] == defaultWrapBeginCharacter && i > 0 {
+		if src[i] == "$" && i > 0 {
 			jdxJ = i
 		}
 	}
@@ -230,7 +232,7 @@ func (j *jqer) jqState(l *lexer.L) lexer.StateFunc {
 		l.Emit(token)
 
 		// remove closing '}'
-		mover(len(j.options.WrapLeftSeparator), true)
+		mover(len(j.options.WrapRightSeparator), true)
 		l.Ignore()
 
 		return j.jqState
@@ -245,6 +247,7 @@ func (j *jqer) jqState(l *lexer.L) lexer.StateFunc {
 
 func (j *jqer) recurseIntoString(data interface{}, s string) ([]interface{}, error) {
 	out := make([]interface{}, 0)
+	s = strings.TrimSpace(s)
 	l := lexer.New(s, j.jqState)
 	l.Start()
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org