[pbuilder] 02/02: satisfydepends-funcs: Make get_source_control_field() more robust

Mattia Rizzolo mattia at debian.org
Fri Jan 6 10:24:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch master
in repository pbuilder.

commit b60c6b731fcb28c20eca13d9d133d596f65a6c8e
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Mon Jan 2 16:54:33 2017 +0000

    satisfydepends-funcs: Make get_source_control_field() more robust
    
    + Fix parsing of a field with a preceeding comment
    
    Closes: #847944
    Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
 pbuilder-satisfydepends-funcs        | 28 ++++++++++++++++++++--------
 t/test_pbuilder-satisfydepends-funcs | 31 +++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/pbuilder-satisfydepends-funcs b/pbuilder-satisfydepends-funcs
index 60f8eca..de7233e 100755
--- a/pbuilder-satisfydepends-funcs
+++ b/pbuilder-satisfydepends-funcs
@@ -55,27 +55,37 @@ checkbuilddep_versiondeps() {
 get_source_control_field() {
     local field="$1"
 
-    sed -n -e "s/^$field://i" -e '
-t store
+    sed -n '
+# Skip PGP header
 /^-----BEGIN PGP SIGNED MESSAGE-----$/ {
     : pgploop
     n
-    /^$/ d
+    /^$/ b leadloop
     b pgploop
 }
+
+# Skip empty lines/comments
 : leadloop
 /^[ \t]*$/ {
     n
-    /^$/ d
     b leadloop
 }
 /^#/ {
     n
-    /^$/ d
     b leadloop
 }
-/^$/q
-d
+
+# First line of source paragraph
+: sourceloop
+# Strip field name from line if present
+s/^'"$field"'://i
+# If field present, print normalised contents
+t store
+# Otherwise, check for end of paragraph or ignore
+/^[ \t]*$/q
+n
+b sourceloop
+
 : store
 H
 : loop
@@ -106,7 +116,9 @@ s/(\(>>\|>=\|>\|==\|=\|<=\|<<\|<\|!=\) *\([^)]*\))/(\1 \2)/g
 # normalize space at beginning and end of line
 s/^ *//
 s/ *$//
-p' \
+p
+n
+b sourceloop' \
         "$DEBIAN_CONTROL"
 }
 
diff --git a/t/test_pbuilder-satisfydepends-funcs b/t/test_pbuilder-satisfydepends-funcs
index cced2d1..b921e81 100755
--- a/t/test_pbuilder-satisfydepends-funcs
+++ b/t/test_pbuilder-satisfydepends-funcs
@@ -57,6 +57,25 @@ EOF
     get_build_deps
 }
 
+test_get_build_deps_comment_between_lines() {
+    local BINARY_ARCH="$1"
+    cat <<EOF >"$DEBIAN_CONTROL"
+Source: foo
+# foo
+Build-Depends: bar
+EOF
+    get_build_deps
+}
+
+test_get_build_deps_one_line_preceding_comment() {
+    local BINARY_ARCH="all"
+    cat << EOF >"$DEBIAN_CONTROL"
+# Preceding comment
+Build-Depends: blabla
+EOF
+    get_build_deps
+}
+
 test_get_build_deps_one_line_trailing_comment() {
     local BINARY_ARCH="all"
     cat << EOF >"$DEBIAN_CONTROL"
@@ -66,6 +85,15 @@ EOF
     get_build_deps
 }
 
+test_get_build_deps_one_line_preceding_blank() {
+    local BINARY_ARCH="all"
+    cat << EOF >"$DEBIAN_CONTROL"
+
+Build-Depends: blabla
+EOF
+    get_build_deps
+}
+
 test_get_build_deps_dsc() {
     cat <<EOF >"$DEBIAN_CONTROL"
 -----BEGIN PGP SIGNED MESSAGE-----
@@ -123,7 +151,10 @@ expect_output "autotools-dev (>= 1.2), debhelper, quilt (<< 12:0), libwxgtk2.8-d
 expect_output "autotools-dev (>= 1.2), debhelper, quilt (<< 12:0), libwxgtk2.8-dev, test [amd64 i386], test1, test2 [!i386 !amd64], test3 | test4, test5" \
     test_get_build_deps "all"
 expect_output "bar" test_get_build_deps_source_para_only "any"
+expect_output "bar" test_get_build_deps_comment_between_lines "any"
+expect_output "blabla" test_get_build_deps_one_line_preceding_comment
 expect_output "blabla" test_get_build_deps_one_line_trailing_comment
+expect_output "blabla" test_get_build_deps_one_line_preceding_blank
 
 
 expect_fail checkbuilddep_archdeps "foo [amd64]" "amd64"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pbuilder/pbuilder.git



More information about the Pbuilder-maint mailing list