Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
2b92198d
Commit
2b92198d
authored
Jan 10, 2024
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jan 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract escapeCSVValue util to its own module
parent
96a89f3f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
+34
-8
csv.ts
src/shared/csv.ts
+13
-0
csv-test.js
src/shared/test/csv-test.js
+20
-0
annotations-exporter.ts
src/sidebar/services/annotations-exporter.ts
+1
-8
No files found.
src/shared/csv.ts
0 → 100644
View file @
2b92198d
/**
* Escape a CSV field value (see https://www.ietf.org/rfc/rfc4180.txt)
*
* - foo -> foo
* - foo,bar -> "foo,bar"
* - with "quoted" text -> "with ""quoted"" text"
*/
export
function
escapeCSVValue
(
value
:
string
):
string
{
if
(
/
[
",
\n\r]
/
.
test
(
value
))
{
return
`"
${
value
.
replace
(
/"/g
,
'""'
)}
"`
;
}
return
value
;
}
src/shared/test/csv-test.js
0 → 100644
View file @
2b92198d
import
{
escapeCSVValue
}
from
'../csv'
;
describe
(
'escapeCSVValue'
,
()
=>
{
[
{
value
:
'foo'
,
expected
:
'foo'
},
{
value
:
'foo,bar'
,
expected
:
'"foo,bar"'
},
{
value
:
'with
\
r carriage return'
,
expected
:
'"with
\
r carriage return"'
},
{
value
:
`multiple
lines`
,
expected
:
`"multiple
lines"`
,
},
{
value
:
'with "quotes"'
,
expected
:
'"with ""quotes"""'
},
].
forEach
(({
value
,
expected
})
=>
{
it
(
'escapes values'
,
()
=>
{
assert
.
equal
(
escapeCSVValue
(
value
),
expected
);
});
});
});
src/sidebar/services/annotations-exporter.ts
View file @
2b92198d
import
{
escapeCSVValue
}
from
'../../shared/csv'
;
import
{
trimAndDedent
}
from
'../../shared/trim-and-dedent'
;
import
type
{
APIAnnotationData
,
Profile
}
from
'../../types/api'
;
import
{
...
...
@@ -117,14 +118,6 @@ export class AnnotationsExporter {
defaultAuthority
,
});
const
escapeCSVValue
=
(
value
:
string
):
string
=>
{
// If the value contains a comma, newline or double quote, then wrap it in
// double quotes and escape any existing double quotes.
if
(
/
[
",
\n]
/
.
test
(
value
))
{
return
`"
${
value
.
replace
(
/"/g
,
'""'
)}
"`
;
}
return
value
;
};
const
annotationToRow
=
(
annotation
:
APIAnnotationData
)
=>
[
annotation
.
created
,
...
...
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