Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
codeberg.org/japh/psv
psv
was initially created to help write "nice looking tables for gherkin
scenarios". Don't worry if you don't know what "gherkin scenarios" means, the
important bits are "nice looking" and "tables [of data in a text file]"
Now, psv
is a unix command line utility and go package to help
maintain and utilise data in simple, text-based
tables using a variant of the Pipe Separated Values format.
In short, psv
helps you
"draw" tables of data in text files
and/or use tabular data programmatically.
For example, psv
can help you turn this, deliberately sloppily hacked up text
(for demonstration purposes):
Controls
+--+
|key|action | alternative
| - | --- |
|h|left
| j|down
|k |up
| l | right ||||||||
: :
| :wq | write & quit | ZZ
+----------
into this:
Controls
+-----+--------------+-------------+
| key | action | alternative |
| --- | ------------ | ----------- |
| h | left | |
| j | down | |
| k | up | |
| l | right | |
: : : :
| :wq | write & quit | ZZ |
+----------------------------------+
with a single call to psv
(in this case, the vim 1
command: vip!psv
2).
The magic being that each line beginning with a |
is split into cells and
re-formatted so they all get the same level of indentation, that all columns
line up nicely and that any superfluous or missing |
's are removed or added
as needed. Additionally, the : : :
line is also considered to be part of the
table and is aligned appropriately.
(see ruler formatting)
psv
Tables can also help improve the readibility of test data.
Here is an example of an actual test suite (containing 14 individual unit
tests) from psv
's own unit testing code (sort_test.go
):
func TestSingleSectionSorting(t *testing.T) {
testTable, _ := psv.TableFromString(`
| 0 | b | 3 | partial
| 1 | D
| 2 | E | 5
| 3 | a | 4 | unequal
| 4 | c | 20
| 5 | C | 10 | row | lengths
| 6 | e | 5
| 7 | d | 7
`)
testCases := sortingTestCasesFromTable(`
| name | sort | columns | exp-col | exp-rows |
| ---------------------------- | ----- | ------- | ------- | --------------- |
| no sort | false | | | 0 1 2 3 4 5 6 7 |
| default sort | | | | 0 1 2 3 4 5 6 7 |
| sort only when asked to | false | 2 | | 0 1 2 3 4 5 6 7 |
| reverse default sort | | ~ | | 7 6 5 4 3 2 1 0 |
| reverse reverse default sort | | ~~ | | 0 1 2 3 4 5 6 7 |
| indexed column sort | | 2 | | 3 0 4 5 7 1 6 2 |
| indexed column sort | | 2 | 2 | a b c C d D e E |
| reverse column sort | | ~2 | | 2 6 1 7 5 4 0 3 |
| third column sort | | 3 | | 1 5 4 0 3 2 6 7 |
| numeric sort | | #3 | | 1 0 3 2 6 7 5 4 |
| reverse numeric sort | | ~#3 | | 4 5 7 6 2 3 0 1 |
| numeric reverse sort | | #~3 | | 4 5 7 6 2 3 0 1 |
| reverse reverse column sort | | ~ #~3 | | 1 0 3 2 6 7 5 4 |
| partial column sort | | 4 2 | | 4 7 1 6 2 0 5 3 |
| non-existent column sort | | 9 | | 0 1 2 3 4 5 6 7 |
`)
runSortingTestCases(t, testTable, testCases)
}
In the example above, two tables are defined:
testTable
is the reference table to be tested
psv
testCases
then defines a series of individual unit tests to be run on testTable
|name|...
and |---|...
) define a header for the table
psv
infers(!) that "a single, separate row, followed by a ruler"
means that the text in each cell defines the name of each respective column,
for all following rows, or until another header is found.sortingTestCase
structssortingTestCasesFromTable
function in the source code for detailstestTable
testCases
table
psv
to reformat the table if your column alignment gets messed up :smile:sortingTestCasesFromTable()
function converts the table of strings into a
slice of sortingTestCase
structsfinally, the runSortingTestCases()
function sorts the testTable
according
to the conditions in each sortingTestCase
and checks that the results match the
expectations.
psv
reads, formats and writes simple tables of data in text files.
In doing so, psv
focuses on human readibility
and ease of use, rather than trying to provide a loss-less,
ubiquitous, machine-readable data transfer format.
The same could be said of
markdown, and indeed, psv
can
be used to generate
github-style markdown tables
that look nice in their markdown source code, and not just after they have been
converted to HTML by the markdown renderer.
Another intended use case is data tables in Gherkin files, which are a central component of Behaviour Driven Development (BDD).
However, the real reason for creating psv
was to be able to use text tables
as the source of data for running automated tests. Hence the
go package.
psv
go packagepsv
is not intended to replace spreadsheets etc :smile:
Among a myriad of other non-features, the following are definitely not supported by psv
:
|
characters in a cell's data+
and -
signs confuse go's collators :frowning:)psv
is a single go binary with no external dependenciespsv
go package is a single package, also with no external
dependecies other than go's standard packages
psv
actions occur locally (no network access required)psv
can also be read be psv
psv
again must not change the table in any wayadd ability to configure the scanner
-I
detect indent by capturing the indent before the first |
encountered+
and -
as data-rh '-'
horizontal ruler-ro '|'
outer ruler-ri ':'
inner ruler-rc '+'
corners-rp 'ophi'
o
outer vertical rulerp
padding characterh
horizontal ruler (default: same as padding character)i
inner vertical ruler (default: same as outer ruler) Replace table.Data
with table.DataRows
psv
consists of two components: the psv
command and the psv
go package.
To use the psv
command, you only need the psv
binary in your
PATH
, e.g. ~/bin/psv
(see binary installation below).
If you don't want to install "a binary, downloaded from the 'net", you can download the source, (inspect it :smile:), and build your own version.
Clone the psv
git repository and use make
to build, test and install psv
in your $GOBIN
directory (typically $GOPATH/bin
or ~/Go/bin
)
git clone -o codeberg https://codeberg.org/japh/psv
cd psv
make install
psv -v
Note: currently only available for darwin amd64 (64-bit Intel Macs)
psv.gz
from https://codeberg.org/japh/psv/releasespsv.gz
with gpg --verify psv.gz.asc
psv.gz
's checksums against those provided with shasum -c psv.gz.sha256
psv.gz
with gunzip psv.gz
psv
to any directory in your $PATH
, or use it directly via ./psv
chmod +x psv
Now you can use the psv
command...
psv
Package In Go ProjectsTo use psv
in your go project, simply import codeberg.org/japh/psv
and go mod tidy
will download it, build it and make it available for your project.
See the psv
package documentation for the API and code examples.
csv, tsv and delimeter-separated-values tables | wikipedia
table.SetHeader
, table.SetFooter()
interface|
, \
, \n
and \r
is nice
| " " |
could be used by psv
to represent a spaceCopyright 2022 Stephen Riehm japh-codeberg@opensauce.de
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.