Open Vergil0327 opened 5 years ago
How should a new line break the JSON format? It's still properly quoted and valid JSON.
I am also having this issue, no JSON parser (that are compliant with the JSON spec) will accept this object. For example: https://docs.python.org/3.7/library/json.html
JSON (JavaScript Object Notation), specified by RFC 7159 (which obsoletes RFC 4627) and by ECMA-404, is a lightweight data interchange format inspired by JavaScript object literal syntax (although it is not a strict subset of JavaScript [1] ).
Per RFC7159, Section 7. Strings:
All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).
U+000A
, LINE FEED (LF), and U+000D
, CARRIAGE RETURN (CR), need therefore to be escaped as per the RFC7159 spec.
To add: any of the above-mentioned characters need to be escaped, so the build.message
should preferably run through a JSON parser.
The RenderTrim method of drone-template-lib is processed, but there is no space before the newline character at the end of the message, resulting in invalid processing.
My message example:
更新个信息看看先\n
func RenderTrim(template string, playload interface{}) (string, error) {
out, err := Render(template, playload)
return strings.Trim(out, " \n"), err
}
That's not the issue. You are getting the implementation of trim wrong, you can see it at https://golang.org/pkg/strings/#Trim.
Just a guess, but maybe you can use to Json from http://masterminds.github.io/sprig/defaults . html to properly format the message in json.
Seems that trim
is a way to got - {{trim build.message}}
.
Trigger from git source add \n
affter commit message
You can try
"message": "${DRONE_COMMIT_MESSAGE//"/}"
This is my webhook part of .drone.yml
When I push commit and my commit message is "test" (
git commit -m "test"
), webhook will parse result as belowOutput result from drone.io:
How can I fix this ?