diff --git a/src/notORM.sh b/src/notORM.sh index 0adf36e..887f741 100755 --- a/src/notORM.sh +++ b/src/notORM.sh @@ -319,11 +319,13 @@ data_yeet() { _sed_sanitize() { _trim_control "$1" - echo -n "$tr" | xxd -p | tr -d '\n' | sed 's/../\\x&/g' + # first, replace backslashes with even more backslashes (workaround for sed bug) + # then, do the actual sanitization, take whole expr as a hexstring and pass it on. + echo -n "$tr" | sed 's/\\/\\\\/g' | xxd -p | tr -d '\n' | sed 's/../\\x&/g' } _sed_sanitize_array() { - echo -n "$1" | xxd -p | tr -d '\n' | sed 's/../\\x&/g' + echo -n "$1" | sed 's/\\/\\\\/g' | xxd -p | tr -d '\n' | sed 's/../\\x&/g' } # _trim_control(string) -> $tr diff --git a/tests/04-notORM.sh b/tests/04-notORM.sh index afde06d..2ad6764 100644 --- a/tests/04-notORM.sh +++ b/tests/04-notORM.sh @@ -88,6 +88,27 @@ notORM_replace_oldsyntax() { } } +notORM_backslashes() { + tst() { + a=('\0meow') + data_add "$store" a + a=('awawa') + data_add "$store" a + + # checks whether data didn't get mangled and can be retrieved + data_get "$store" { '\0meow' } || return $? + + # tries to delete the entry, then checks if it got matched + data_yeet "$store" { '\0meow' } + data_get "$store" { '\0meow' } + if [[ $? == 0 ]]; then + return 1 + fi + + return 0 + } +} + subtest_list=( notORM_add_get notORM_get_multiline @@ -97,4 +118,5 @@ subtest_list=( notORM_yeet notORM_yeet_multiple_filters notORM_replace_oldsyntax + notORM_backslashes )