Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2af69ccf
Commit
2af69ccf
authored
May 03, 2019
by
psschand
Committed by
Ryan McKinley
May 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CSV: escape quotes in toCSV (#16874)
parent
c3a52049
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
2 deletions
+5
-2
packages/grafana-ui/src/utils/csv.test.ts
+3
-0
packages/grafana-ui/src/utils/csv.ts
+1
-1
packages/grafana-ui/src/utils/testdata/roundtrip.csv
+1
-1
No files found.
packages/grafana-ui/src/utils/csv.test.ts
View file @
2af69ccf
...
...
@@ -48,11 +48,13 @@ function norm(csv: string): string {
describe
(
'write csv'
,
()
=>
{
it
(
'should write the same CSV that we read'
,
()
=>
{
const
firstRow
=
[
10
,
'this "has quotes" inside'
,
true
];
const
path
=
__dirname
+
'/testdata/roundtrip.csv'
;
const
csv
=
fs
.
readFileSync
(
path
,
'utf8'
);
const
data
=
readCSV
(
csv
);
const
out
=
toCSV
(
data
,
{
headerStyle
:
CSVHeaderStyle
.
full
});
expect
(
data
.
length
).
toBe
(
1
);
expect
(
data
[
0
].
rows
[
0
]).
toEqual
(
firstRow
);
expect
(
data
[
0
].
fields
.
length
).
toBe
(
3
);
expect
(
norm
(
out
)).
toBe
(
norm
(
csv
));
...
...
@@ -63,6 +65,7 @@ describe('write csv', () => {
const
f
=
readCSV
(
shorter
);
const
fields
=
f
[
0
].
fields
;
expect
(
fields
.
length
).
toBe
(
3
);
expect
(
f
[
0
].
rows
[
0
]).
toEqual
(
firstRow
);
expect
(
fields
.
map
(
f
=>
f
.
name
).
join
(
','
)).
toEqual
(
'a,b,c'
);
// the names
});
});
packages/grafana-ui/src/utils/csv.ts
View file @
2af69ccf
...
...
@@ -266,7 +266,7 @@ function writeValue(value: any, config: CSVConfig): string {
const
str
=
value
.
toString
();
if
(
str
.
includes
(
'"'
))
{
// Escape the double quote characters
return
config
.
quoteChar
+
str
.
replace
(
'"'
,
'""'
)
+
config
.
quoteChar
;
return
config
.
quoteChar
+
str
.
replace
(
/"/gi
,
'""'
)
+
config
.
quoteChar
;
}
if
(
str
.
includes
(
'
\
n'
)
||
str
.
includes
(
config
.
delimiter
))
{
return
config
.
quoteChar
+
str
+
config
.
quoteChar
;
...
...
packages/grafana-ui/src/utils/testdata/roundtrip.csv
View file @
2af69ccf
#name#a,b,c
#type#number,string,boolean
#unit#ms,,s
10,
AA
,true
10,
"this ""has quotes"" inside"
,true
20,XX,false
30,YY,false
40,ZZ,true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment