Welcome! Log In Create A New Profile

Advanced

[njs] Fixed nxt_file_dirname() for paths with no dir component.

Dmitry Volyntsev
March 23, 2019 08:40AM
details: https://hg.nginx.org/njs/rev/aaf68d999559
branches:
changeset: 838:aaf68d999559
user: hongzhidao <hongzhidao@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(".");
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed nxt_file_dirname() for paths with no dir component.

Dmitry Volyntsev 254 March 23, 2019 08:40AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 301
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready