diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Show an absolute link target as text
A symlink to /etc/passwd was resolved against the tree and linked to
etc/passwd inside it, a different file or none at all.
| -rw-r--r-- | source/ui-tree.c | 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0104-tree.sh | 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 files changed, 30 insertions, 3 deletions
diff --git a/source/ui-tree.c b/source/ui-tree.c index c030134..51ab9ff 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -336,9 +336,10 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, } else { strbuf_addbuf(&linkpath, &fullpath); strbuf_addf(&linkpath, "/../%s", buf); - // A target climbing above the tree root has nothing to - // link to. - if (strbuf_normalize_path(&linkpath)) + // A target climbing above the tree root, or one given + // from the root of the filesystem, has nothing in the + // tree to link to. + if (buf[0] == '/' || strbuf_normalize_path(&linkpath)) html_txt(buf); else cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, walk->rev, diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index 48c8406..a2ec3c2 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -82,4 +82,30 @@ test_expect_success 'a file row still offers blame' ' grep ">blame</a>" tmp ' +# A link target inside the tree becomes a link, while an absolute one names a +# file on whatever machine checks the tree out, not a path in the tree. +test_expect_success 'only a link target inside the tree is linked' ' + test_create_repo repos/links && + ( + cd repos/links && + echo hi >target.txt && + git add target.txt && + rel=$(printf target.txt | git hash-object -w --stdin) && + abs=$(printf /etc/passwd | git hash-object -w --stdin) && + git update-index --add --cacheinfo 120000,$rel,rel && + git update-index --add --cacheinfo 120000,$abs,abs && + git commit -m links + ) && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "repo.url=links" && + echo "repo.path=$PWD/repos/links/.git" + } >linksrc && + CGIT_CONFIG="$PWD/linksrc" QUERY_STRING="url=links/tree/" cgit >tmp && + grep " -> <a class=.ls-blob. href=./links/tree/target.txt.>target.txt</a>" tmp && + grep " -> /etc/passwd</td>" tmp && + ! grep "href=./links/tree/etc/passwd" tmp +' + test_done |
