mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-19 02:02:55 +02:00
Fix yaml output single quote (#814)
Fix #659 Reviewed-on: https://gitea.com/gitea/tea/pulls/814
This commit is contained in:
@ -104,15 +104,17 @@ func (t *table) fprint(f io.Writer, output string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// outputTable prints structured data as table
|
// outputTable prints structured data as table
|
||||||
func outputTable(f io.Writer, headers []string, values [][]string) {
|
func outputTable(f io.Writer, headers []string, values [][]string) error {
|
||||||
table := tablewriter.NewWriter(f)
|
table := tablewriter.NewWriter(f)
|
||||||
if len(headers) > 0 {
|
if len(headers) > 0 {
|
||||||
table.Header(headers)
|
table.Header(headers)
|
||||||
}
|
}
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
table.Append(value)
|
if err := table.Append(value); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
table.Render()
|
}
|
||||||
|
return table.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
// outputSimple prints structured data as space delimited value
|
// outputSimple prints structured data as space delimited value
|
||||||
@ -147,7 +149,7 @@ func outputYaml(f io.Writer, headers []string, values [][]string) {
|
|||||||
if strconv.Itoa(intVal) == val {
|
if strconv.Itoa(intVal) == val {
|
||||||
fmt.Fprintf(f, " %s: %s\n", headers[j], val)
|
fmt.Fprintf(f, " %s: %s\n", headers[j], val)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(f, " %s: '%s'\n", headers[j], val)
|
fmt.Fprintf(f, " %s: '%s'\n", headers[j], strings.ReplaceAll(val, "'", "''"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,4 +48,25 @@ func TestPrint(t *testing.T) {
|
|||||||
assert.EqualValues(t, "\\abc", result[4].A)
|
assert.EqualValues(t, "\\abc", result[4].A)
|
||||||
assert.EqualValues(t, "'def\\", result[4].B)
|
assert.EqualValues(t, "'def\\", result[4].B)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf.Reset()
|
||||||
|
|
||||||
|
tData.fprint(buf, "yaml")
|
||||||
|
|
||||||
|
assert.Equal(t, `-
|
||||||
|
A: 'new a'
|
||||||
|
B: 'some bbbb'
|
||||||
|
-
|
||||||
|
A: 'AAAAA'
|
||||||
|
B: 'b2'
|
||||||
|
-
|
||||||
|
A: '"abc'
|
||||||
|
B: '"def'
|
||||||
|
-
|
||||||
|
A: '''abc'
|
||||||
|
B: 'de''f'
|
||||||
|
-
|
||||||
|
A: '\abc'
|
||||||
|
B: '''def\'
|
||||||
|
`, buf.String())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user