From 64fd5d1836ad66dd13a66e8b29b01e97aff5f12a Mon Sep 17 00:00:00 2001 From: sdomi Date: Thu, 1 May 2025 10:58:03 +0200 Subject: [PATCH 1/2] notORM: fix a bug around search terms containing a backslash --- src/notORM.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 From 93271da824951a6f4969ef2828d83030102ac36d Mon Sep 17 00:00:00 2001 From: sdomi Date: Thu, 1 May 2025 11:05:34 +0200 Subject: [PATCH 2/2] tests: add testcase for notORM's backslash handling --- tests/04-notORM.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 )