diff options
-rw-r--r-- | stream.c | 7 | ||||
-rw-r--r-- | tests/018/path.tl | 36 | ||||
-rw-r--r-- | txr.1 | 13 |
3 files changed, 37 insertions, 19 deletions
@@ -5040,7 +5040,7 @@ val short_suffix(val name, val alt_in) const wchar_t *dot = wcsrchr(str, '.'); const wchar_t *sl = if3(dot, wcspbrk(dot + 1, psc), 0); - if (!dot || (sl && sl[1])) { + if (!dot || (sl && sl[1]) || dot == str || wcschr(psc, dot[-1])) { return default_null_arg(alt_in); } else { wchar_t *suff = chk_strdup(dot + 1); @@ -5063,7 +5063,10 @@ val long_suffix(val name, val alt_in) while (dot && (sl = wcspbrk(dot, psc)) && sl[1]) dot = wcschr(sl + 1, '.'); - if (!dot || (sl && sl[1])) { + if (dot && (dot == str || wcschr(psc, dot[-1]))) + dot = wcschr(dot + 1, '.'); + + if (!dot || dot == str) { return default_null_arg(alt_in); } else { wchar_t *suff = chk_strdup(dot + 1); diff --git a/tests/018/path.tl b/tests/018/path.tl index 3dcb5eb3..a00b9465 100644 --- a/tests/018/path.tl +++ b/tests/018/path.tl @@ -7,14 +7,15 @@ (short-suffix "" 0) 0 (short-suffix "a") nil (short-suffix "a" 0) 0 - (short-suffix ".") "" + (short-suffix ".") nil (short-suffix "a.") "" (short-suffix "a.b.") "" - (short-suffix ".c") "c" + (short-suffix ".c") nil (short-suffix "a.c") "c" (short-suffix "a.b.c") "c" (short-suffix "foo.txt.gz") "gz" - (short-suffix ".gz") "gz") + (short-suffix "txt.gz") "gz" + (short-suffix ".gz") nil) (mtest (long-suffix 42) :error @@ -23,24 +24,29 @@ (long-suffix "" 0) 0 (long-suffix "a") nil (long-suffix "a" 0) 0 - (long-suffix ".") "" + (long-suffix ".") nil (long-suffix "a.") "" (long-suffix "a.b.") "b." - (long-suffix ".c") "c" + (long-suffix ".c") nil (long-suffix "a.c") "c" (long-suffix "a.b.c") "b.c" (long-suffix "foo.txt.gz") "txt.gz" - (long-suffix ".gz") "gz" - (long-suffix ".txt.gz") "txt.gz") + (long-suffix ".gz") nil + (long-suffix ".txt.gz") "gz" + (long-suffix "/.txt.gz") "gz" + (long-suffix "a/.txt.gz") "gz") (mtest (short-suffix "/") nil (short-suffix "a/") nil - (short-suffix ".a/") "a" + (short-suffix "/.") nil + (short-suffix "a/.") nil + (short-suffix ".a/") nil (short-suffix ".a/b") nil + (short-suffix ".a/c.b") "b" (short-suffix ".a/b/") nil - (short-suffix ".a/b/.b") "b" - (short-suffix ".a/b/.b/") "b" + (short-suffix ".a/b/.b") nil + (short-suffix ".a/b/.b/") nil (short-suffix ".a/b/c.b") "b" (short-suffix ".a/b/c.b/") "b" (short-suffix ".a/b/c.b//") nil) @@ -48,13 +54,17 @@ (mtest (long-suffix "/") nil (long-suffix "a/") nil - (long-suffix ".a/") "a" + (long-suffix "/.") nil + (long-suffix "a/.") nil + (long-suffix ".a/") nil (long-suffix ".a/b") nil (long-suffix ".a/b/") nil - (long-suffix ".a/b/.b") "b" - (long-suffix ".a/b/.b/") "b" + (long-suffix ".a/b/.b") nil + (long-suffix ".a/b/.b/") nil (long-suffix ".a/b/c.b") "b" (long-suffix ".a/b/c.b/") "b" (long-suffix "a.b/c.d.e") "d.e" (long-suffix "a.b/c.d.e/") "d.e" + (long-suffix "a.b/c.d.e/f") nil + (long-suffix "a.b/c.d.e/f.g.h") "g.h" (long-suffix "a.b/c.d.e//") nil) @@ -57196,7 +57196,8 @@ What it means for to have a suffix delimiter is that the .code . character occurs somewhere in the last component of -.metn path . +.metn path , +other than as the character of that component. What constitutes the last component is specified in more detail below. @@ -57236,8 +57237,10 @@ extracted from this last component. .verb (short-suffix "") -> nil - (short-suffix ".") -> "" + (short-suffix ".") -> nil (short-suffix "abc") -> nil + (short-suffix ".abc") -> nil + (short-suffix "/.abc") -> nil (short-suffix "abc" "") -> "" (short-suffix "abc.") -> "" (short-suffix "abc.tar") -> "tar" @@ -57247,10 +57250,12 @@ extracted from this last component. (short-suffix "x.y.z/abc.tar.gz//") -> nil (long-suffix "") -> nil - (long-suffix ".") -> "" + (long-suffix ".") -> nil (long-suffix "abc") -> nil + (long-suffix ".abc") -> nil + (long-suffix "/.abc") -> nil (long-suffix "abc.") -> "" - (long-suffix "abc.tar") -> "txt" + (long-suffix "abc.tar") -> "tar" (long-suffix "abc.tar.gz") -> "tar.gz" (long-suffix "abc.tar.gz/") -> "tar.gz" (long-suffix "x.y.z/abc.tar.gz/") -> "tar.gz" |