generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from dorny/list-files-csv
Add list-files: csv format
- Loading branch information
Showing
11 changed files
with
133 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: "Build" | ||
on: | ||
push: | ||
paths-ignore: [ '*.md' ] | ||
branches: | ||
- master | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: "Pull Request Verification" | ||
on: | ||
pull_request: | ||
paths-ignore: [ '*.md' ] | ||
branches: | ||
- master | ||
- develop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {csvEscape} from '../src/list-format/csv-escape' | ||
|
||
describe('csvEscape() backslash escapes every character except subset of definitely safe characters', () => { | ||
test('simple filename should not be modified', () => { | ||
expect(csvEscape('file.txt')).toBe('file.txt') | ||
}) | ||
|
||
test('directory separator should be preserved and not escaped', () => { | ||
expect(csvEscape('path/to/file.txt')).toBe('path/to/file.txt') | ||
}) | ||
|
||
test('filename with spaces should be quoted', () => { | ||
expect(csvEscape('file with space')).toBe('"file with space"') | ||
}) | ||
|
||
test('filename with "," should be quoted', () => { | ||
expect(csvEscape('file, with coma')).toBe('"file, with coma"') | ||
}) | ||
|
||
test('Double quote should be escaped by another double quote', () => { | ||
expect(csvEscape('file " with double quote')).toBe('"file "" with double quote"') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Returns filename escaped for CSV | ||
// Wraps file name into "..." only when it contains some potentially unsafe character | ||
export function csvEscape(value: string): string { | ||
if (value === '') return value | ||
|
||
// Only safe characters | ||
if (/^[a-zA-Z0-9._+:@%/-]+$/m.test(value)) { | ||
return value | ||
} | ||
|
||
// https://tools.ietf.org/html/rfc4180 | ||
// If double-quotes are used to enclose fields, then a double-quote | ||
// appearing inside a field must be escaped by preceding it with | ||
// another double quote | ||
return `"${value.replace(/"/g, '""')}"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters