From b4ef9954e717830ffc497e9651217553656e1c7e Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Sat, 31 Oct 2015 16:49:55 +0000 Subject: [PATCH] Fix #120 by stripping comments from the end of lines. The debug printing is also moved after variable substitution. Now it prints: foo/template: _var foo foo/template: pkgname foo It used to print: foo/template: _var foo foo/template: pkgname ${_var} --- bin/xbps-checkvers/main.c | 23 ++++++++++++++++------- tests/xbps/xbps-checkvers/checkvers.sh | 1 - 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bin/xbps-checkvers/main.c b/bin/xbps-checkvers/main.c index c1bc97c1..713e4b06 100644 --- a/bin/xbps-checkvers/main.c +++ b/bin/xbps-checkvers/main.c @@ -399,7 +399,7 @@ rcv_get_pkgver(rcv_t *rcv) size_t klen, vlen; map_item_t _item; map_item_t *item = NULL; - char c, *ptr = rcv->ptr, *e, *p, *k, *v; + char c, *ptr = rcv->ptr, *e, *p, *k, *v, *comment; uint8_t vars = 0; while ((c = *ptr) != '\0') { @@ -439,18 +439,22 @@ rcv_get_pkgver(rcv_t *rcv) if (v[vlen-1] == '"') { vlen--; } + comment = strchr(v, '#'); + if (comment && comment < p) { + while (v[vlen-1] != '#') { + vlen--; + } + vlen--; + while (isspace(v[vlen-1])) { + vlen--; + } + } if (vlen == 0) { goto nextline; } _item = map_add_n(rcv->env, k, klen, v, vlen); item = &rcv->env->items[_item.i]; - if (rcv->xhp.flags & XBPS_FLAG_DEBUG) { - printf("%s: %.*s %.*s\n", rcv->fname, - (int)item->k.len, item->k.s, - (int)item->v.len, item->v.s); - } - if (strchr(v, '$')) { assert(item); assert(item->v.s); @@ -462,6 +466,11 @@ rcv_get_pkgver(rcv_t *rcv) } else { item->v.vmalloc = 0; } + if (rcv->xhp.flags & XBPS_FLAG_DEBUG) { + printf("%s: %.*s %.*s\n", rcv->fname, + (int)item->k.len, item->k.s, + (int)item->v.len, item->v.s); + } if (strncmp("pkgname", k, klen) == 0) { rcv->have_vars |= GOT_PKGNAME_VAR; vars++; diff --git a/tests/xbps/xbps-checkvers/checkvers.sh b/tests/xbps/xbps-checkvers/checkvers.sh index 64c37c02..aff6318a 100755 --- a/tests/xbps/xbps-checkvers/checkvers.sh +++ b/tests/xbps/xbps-checkvers/checkvers.sh @@ -305,7 +305,6 @@ srcpkg_with_a_ref_and_comment_head() { atf_set "descr" "xbps-checkvers(8): test when srcpkg does set a ref in pkgname/version/revision with a comment" } srcpkg_with_a_ref_and_comment_body() { - atf_expect_death "Known bug: see https://github.com/voidlinux/xbps/issues/120" mkdir -p some_repo pkg_A void-packages/srcpkgs/foo cat > void-packages/srcpkgs/foo/template <