[njs] Fixed nxt_file_dirname() for paths with no dir component.
Dmitry Volyntsev
xeioex at nginx.com
Sat Mar 23 12:38:55 UTC 2019
details: https://hg.nginx.org/njs/rev/aaf68d999559
branches:
changeset: 838:aaf68d999559
user: hongzhidao <hongzhidao at gmail.com>
date: Sat Mar 23 14:57:52 2019 +0300
description:
Fixed nxt_file_dirname() for paths with no dir component.
Making it more similar to dirname shell cmd.
This closes #114 issue on Github.
diffstat:
njs/test/njs_unit_test.c | 4 ++--
nxt/nxt_file.c | 12 ++++++++----
2 files changed, 10 insertions(+), 6 deletions(-)
diffs (53 lines):
diff -r 53dc000e8c14 -r aaf68d999559 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Sat Mar 02 20:31:10 2019 +0800
+++ b/njs/test/njs_unit_test.c Sat Mar 23 14:57:52 2019 +0300
@@ -12456,13 +12456,13 @@ nxt_file_dirname_test(njs_vm_t * vm, nxt
nxt_str_t path;
nxt_str_t expected;
} tests[] = {
- { nxt_string(""), nxt_string("") },
+ { nxt_string(""), nxt_string(".") },
{ nxt_string("/"), nxt_string("/") },
{ nxt_string("/a"), nxt_string("/") },
{ nxt_string("///"), nxt_string("///") },
{ nxt_string("///a"), nxt_string("///") },
{ nxt_string("///a/"), nxt_string("///a") },
- { nxt_string("a"), nxt_string("") },
+ { nxt_string("a"), nxt_string(".") },
{ nxt_string("a/"), nxt_string("a") },
{ nxt_string("a//"), nxt_string("a") },
{ nxt_string("p1/p2/name"), nxt_string("p1/p2") },
diff -r 53dc000e8c14 -r aaf68d999559 nxt/nxt_file.c
--- a/nxt/nxt_file.c Sat Mar 02 20:31:10 2019 +0800
+++ b/nxt/nxt_file.c Sat Mar 23 14:57:52 2019 +0300
@@ -38,8 +38,7 @@ nxt_file_dirname(const nxt_str_t *path,
const u_char *p, *end;
if (path->length == 0) {
- *name = nxt_string_value("");
- return;
+ goto current_dir;
}
p = path->start + path->length - 1;
@@ -51,8 +50,7 @@ nxt_file_dirname(const nxt_str_t *path,
end = p + 1;
if (end == path->start) {
- *name = nxt_string_value("");
- return;
+ goto current_dir;
}
/* Stripping trailing slashes. */
@@ -67,4 +65,10 @@ nxt_file_dirname(const nxt_str_t *path,
name->start = path->start;
name->length = p - path->start;
+
+ return;
+
+current_dir:
+
+ *name = nxt_string_value(".");
}
More information about the nginx-devel
mailing list