summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2022-03-31 00:58:40 +0100
committerJo-Philipp Wich <jo@mein.io>2022-03-31 10:22:03 +0200
commite956bcf5d6533de9bbf2bbefae60c32e52348cf9 (patch)
treef5b13152cc76f797a23bb11ecbb175168e6b046e /tests
parenta37f65471c2b69fa588cbf8e9794ff1fe6d04605 (diff)
fs: fix off-by-one in fs.dirname() function
Make sure fs.dirname() doesn't truncate the last character of the returned path. Previously ucv_string_new_length was called with a length which no longer included the last character (which had just been tested not to be a '/' or '.' and hence broke the loop at that point). Signed-off-by: Daniel Golle <daniel@makrotopia.org> [testcase added] Signed-off-by: Paul Spooren <mail@aparcar.org> [testcase folded into this commit and fixed] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/custom/04_bugs/34_dirname_off_by_one16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/custom/04_bugs/34_dirname_off_by_one b/tests/custom/04_bugs/34_dirname_off_by_one
new file mode 100644
index 0000000..34ef7c7
--- /dev/null
+++ b/tests/custom/04_bugs/34_dirname_off_by_one
@@ -0,0 +1,16 @@
+Make sure fs.dirname() doesn't truncate the last character of the
+returned path. Previously ucv_string_new_length was called with a
+length which no longer included the last character (which had just
+been tested not to be a '/' or '.' and hence broke the loop at that
+point).
+
+-- Testcase --
+{%
+ fs = require('fs');
+ printf("%s\n", fs.dirname('/etc/config/wireless'));
+%}
+-- End --
+
+-- Expect stdout --
+/etc/config
+-- End --