[med-svn] [htslib] 11/13: allow spaces in vcf header lines

Andreas Tille tille at debian.org
Sat Jan 30 13:23:57 UTC 2016


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

tille pushed a commit to branch master
in repository htslib.

commit 72cb247f0da6fff117a56b3a18cc3b4d7c2a8e68
Author: Shane McCarthy <sm15 at sanger.ac.uk>
Date:   Mon Jun 1 16:29:55 2015 +0100

    allow spaces in vcf header lines
    
    * allow spaces between keys and values when parsing in header lines
    * these spaces will be dropped when writing out the header
    
    e.g. `##reference=<ID=hs37d5 , Source=blah>` and `##reference=<ID=hs37d5, Source = blah >`
         will become `##reference=<ID=hs37d5,Source=blah>`
    
    Fixes samtools/bcftools#266
---
 vcf.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/vcf.c b/vcf.c
index 00e9196..0c7e879 100644
--- a/vcf.c
+++ b/vcf.c
@@ -293,6 +293,7 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
     while ( *q && *q!='\n' && nopen )
     {
         p = ++q;
+        while ( *q && *q==' ' ) { p++; q++; }
         // ^[A-Za-z_][0-9A-Za-z_.]*$
         if (p==q && *q && (isalpha(*q) || *q=='_'))
         {
@@ -300,6 +301,8 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
             while ( *q && (isalnum(*q) || *q=='_' || *q=='.') ) q++;
         }
         n = q-p;
+        int m = 0;
+        while ( *q && *q==' ' ) { q++; m++; }
         if ( *q!='=' || !n )
         {
             // wrong format
@@ -312,8 +315,9 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
             bcf_hrec_destroy(hrec);
             return NULL;
         }
-        bcf_hrec_add_key(hrec, p, q-p);
+        bcf_hrec_add_key(hrec, p, q-p-m);
         p = ++q;
+        while ( *q && *q==' ' ) { p++; q++; }
         int quoted = *p=='"' ? 1 : 0;
         if ( quoted ) p++, q++;
         while (1)
@@ -329,7 +333,9 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
             }
             q++;
         }
-        bcf_hrec_set_val(hrec, hrec->nkeys-1, p, q-p, quoted);
+        const char *r = q-1;
+        while ( *r && (*r==' ') ) r--;
+        bcf_hrec_set_val(hrec, hrec->nkeys-1, p, r-p+1, quoted);
         if ( quoted ) q++;
         if ( *q=='>' ) { nopen--; q++; }
     }

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



More information about the debian-med-commit mailing list