Runtime error for weird mappings using only the prefix/suffix notation
ericcornelissen opened this issue · 0 comments
ericcornelissen commented
Bug Report
- wordrow version:
v0.4.0-beta
Description
wordrow does not handle mappings that use the prefix/suffix notation in a way that was not intended.
Actual Behaviour
wordrow panics.
Expected Behaviour
wordrow provides an error.
Working Example
- Create a file specifying the following mapping
# mapping.csv
- -,-
- Create a non-empty input file
# inputfile.txt
Hello world!
- Run wordrow using
mapping.csv
as a--map-file
:
$ ./wordrow --map-file ./mapping.csv ./input.txt
Log Output
$ ./wordrow -v -M ./mapping.csv ./inputfile.txt
[Debug] Processing CLI specified map files...
[Debug] Parsing argument './mapping.csv'
[Debug] Reading './mapping.csv'
[Debug] Processing '/media/win/workspace/wordrow/mapping.csv' as a .csv mapping file
[Debug] Processing CLI specified mappings...
[Debug] Processing '/media/win/workspace/wordrow/inputfile.txt' as input file
panic: runtime error: slice bounds out of range [:-1]
goroutine 7 [running]:
github.com/ericcornelissen/wordrow/internal/wordmaps.removePrefixAndSuffixSymbols(0xc0000144ce, 0x1, 0xc00006a598, 0xc000001338)
/media/win/workspace/wordrow/internal/wordmaps/mapping.go:27 +0x206
github.com/ericcornelissen/wordrow/internal/wordmaps.(*Mapping).GetTo(...)
/media/win/workspace/wordrow/internal/wordmaps/mapping.go:165
github.com/ericcornelissen/wordrow/internal/wordmaps.(*Mapping).getReplacement(0xc00000c220, 0xc000014520, 0x2, 0xc000014523, 0x3, 0x0, 0x0)
/media/win/workspace/wordrow/internal/wordmaps/mapping.go:111 +0x3c
github.com/ericcornelissen/wordrow/internal/wordmaps.(*Mapping).Match.func1(0xc000022420, 0xc000014520, 0x10, 0xc00000c220)
/media/win/workspace/wordrow/internal/wordmaps/mapping.go:178 +0x1ca
created by github.com/ericcornelissen/wordrow/internal/wordmaps.(*Mapping).Match
/media/win/workspace/wordrow/internal/wordmaps/mapping.go:172 +0x76