diff options
author | David Kalnischkies <david@kalnischkies.de> | 2019-02-01 14:51:56 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2019-02-01 14:51:56 +0100 |
commit | 5caa8cac3bc0ffa8b5360f3e5d5c84e710eb394b (patch) | |
tree | 5b0c4a1c2a96db9723abe45685bd5db478df7c1e | |
parent | a1d9debedcba071d708b3019b5a649314cccb1f6 (diff) | |
download | apt-5caa8cac3bc0ffa8b5360f3e5d5c84e710eb394b.tar.gz |
Step over empty sections in TagFiles with comments
Implementing a parser with recursion isn't the best idea, but in
practice we should get away with it for the time being to avoid
needless codechurn.
Closes: #920317 #921037
-rw-r--r-- | apt-pkg/tagfile.cc | 8 | ||||
-rwxr-xr-x | test/integration/test-apt-sources-deb822 | 68 | ||||
-rw-r--r-- | test/libapt/tagfile_test.cc | 2 |
3 files changed, 76 insertions, 2 deletions
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 98001afd1..1e7f2867c 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -250,8 +250,12 @@ bool pkgTagFile::Step(pkgTagSection &Tag) d->chunks.erase(d->chunks.begin(), first); } - Tag.Trim(); - return true; + if ((d->Flags & pkgTagFile::SUPPORT_COMMENTS) == 0 || Tag.Count() != 0) + { + Tag.Trim(); + return true; + } + return Step(Tag); } /*}}}*/ // TagFile::Fill - Top up the buffer /*{{{*/ diff --git a/test/integration/test-apt-sources-deb822 b/test/integration/test-apt-sources-deb822 index fdf26fe97..8ffe0abe6 100755 --- a/test/integration/test-apt-sources-deb822 +++ b/test/integration/test-apt-sources-deb822 @@ -14,6 +14,8 @@ BASE='# some comment # that contains a : as well #Types: meep +# a free-standing comment appears + Types: deb #Types: deb-src URIs: http://ftp.debian.org/debian @@ -291,3 +293,69 @@ testsuccessequal --nomsg "'http://ftp.debian.org/debian/dists/stable/InRelease' 'http://ftp.debian.org/debian2/dists/sid/non-free/binary-powerpc/Packages.xz' ftp.debian.org_debian2_dists_sid_non-free_binary-powerpc_Packages 0 'http://ftp.debian.org/debian2/dists/sid/non-free/binary-all/Packages.xz' ftp.debian.org_debian2_dists_sid_non-free_binary-all_Packages 0 'http://ftp.debian.org/debian2/dists/sid/non-free/i18n/Translation-en.xz' ftp.debian.org_debian2_dists_sid_non-free_i18n_Translation-en 0 " aptget update --print-uris + +EXPECTEDUK="'http://ftp.uk.debian.org/debian/dists/stretch/InRelease' ftp.uk.debian.org_debian_dists_stretch_InRelease 0 +'http://ftp.uk.debian.org/debian/dists/stretch/main/source/Sources.xz' ftp.uk.debian.org_debian_dists_stretch_main_source_Sources 0 +'http://ftp.uk.debian.org/debian/dists/stretch/contrib/source/Sources.xz' ftp.uk.debian.org_debian_dists_stretch_contrib_source_Sources 0 +'http://ftp.uk.debian.org/debian/dists/stretch/non-free/source/Sources.xz' ftp.uk.debian.org_debian_dists_stretch_non-free_source_Sources 0 +'http://ftp.uk.debian.org/debian/dists/stretch/main/binary-i386/Packages.xz' ftp.uk.debian.org_debian_dists_stretch_main_binary-i386_Packages 0 +'http://ftp.uk.debian.org/debian/dists/stretch/main/binary-all/Packages.xz' ftp.uk.debian.org_debian_dists_stretch_main_binary-all_Packages 0 +'http://ftp.uk.debian.org/debian/dists/stretch/main/i18n/Translation-en.xz' ftp.uk.debian.org_debian_dists_stretch_main_i18n_Translation-en 0 +'http://ftp.uk.debian.org/debian/dists/stretch/contrib/binary-i386/Packages.xz' ftp.uk.debian.org_debian_dists_stretch_contrib_binary-i386_Packages 0 +'http://ftp.uk.debian.org/debian/dists/stretch/contrib/binary-all/Packages.xz' ftp.uk.debian.org_debian_dists_stretch_contrib_binary-all_Packages 0 +'http://ftp.uk.debian.org/debian/dists/stretch/contrib/i18n/Translation-en.xz' ftp.uk.debian.org_debian_dists_stretch_contrib_i18n_Translation-en 0 +'http://ftp.uk.debian.org/debian/dists/stretch/non-free/binary-i386/Packages.xz' ftp.uk.debian.org_debian_dists_stretch_non-free_binary-i386_Packages 0 +'http://ftp.uk.debian.org/debian/dists/stretch/non-free/binary-all/Packages.xz' ftp.uk.debian.org_debian_dists_stretch_non-free_binary-all_Packages 0 +'http://ftp.uk.debian.org/debian/dists/stretch/non-free/i18n/Translation-en.xz' ftp.uk.debian.org_debian_dists_stretch_non-free_i18n_Translation-en 0 " + +msgcleantest 'Test deb822 sources.list file comments' 'top' +cat > $SOURCES <<EOF +#NOTE: Most preferred source listed first! + + +#=== NEW MULTI-LINE FORMAT =============== +Types: deb deb-src +URIs:http://ftp.uk.debian.org/debian/ +Suites: stretch +Components: main contrib non-free +EOF +testsuccessequal --nomsg "$EXPECTEDUK" aptget update --print-uris + +msgcleantest 'Test deb822 sources.list file comments' 'bottom' +cat > $SOURCES <<EOF +Types: deb deb-src +URIs:http://ftp.uk.debian.org/debian/ +Suites: stretch +Components: main contrib non-free +#=== NEW MULTI-LINE FORMAT =============== + + +#NOTE: Most preferred source listed first! +EOF +testsuccessequal --nomsg "$EXPECTEDUK" aptget update --print-uris + +msgcleantest 'Test deb822 sources.list file comments' 'both' +cat > $SOURCES <<EOF +#=== NEW MULTI-LINE FORMAT =============== + + +#NOTE: Most preferred source listed first! +Types: deb deb-src +URIs:http://ftp.uk.debian.org/debian/ +Suites: stretch +Components: main contrib non-free +#=== NEW MULTI-LINE FORMAT =============== + + +#NOTE: Most preferred source listed first! +EOF +testsuccessequal --nomsg "$EXPECTEDUK" aptget update --print-uris + + +msgcleantest 'Test deb822 sources.list file comments' 'empty' +cat > $SOURCES <<EOF +#=== NEW MULTI-LINE FORMAT =============== + + +EOF +testempty aptget update --print-uris diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc index f455a8dcc..8823ff781 100644 --- a/test/libapt/tagfile_test.cc +++ b/test/libapt/tagfile_test.cc @@ -232,6 +232,8 @@ TEST(TagFileTest, Comments) FileFd fd; createTemporaryFile("commentfile", fd, NULL, "# Leading comments should be ignored.\n" "\n" +"# A wild second comment appears!\n" +"\n" "Source: foo\n" "#Package: foo\n" "Section: bar\n" |