Subject: Re: Bug#186886: wrong assumptions on PIs cause TDG processing to fail

From: Adam DiCarlo <[email-masked]>
Date: 28 Apr 2003 00:23:25 -0500

tags 186886 + pending
thanks

I believe I've fixed this bug in the DSSSL source.  I attach a patch.

The underlying problem is actually just PIs which are in rather
degenerate form, such as '<?dbhtml filename="pe-module.html"??>'.
However, the stylesheets shouldn't die in that way, just because a PI
is bad; now it silently skips over it.  Probably a warning would be
better but I'm lazy. :)

This has been applied upstream and will be in the Debian package once
the next docbook-dsssl releases.

-- 
...Adam Di Carlo...<[email-masked]>.......<URL:http://www.onshored.com/>
=== cd /home/adam/debian/docbook-dsssl/dsssl/html/
=== /usr/bin/cvs diff -u dbpi.dsl

DSA host key for IP address '66.35.250.207' not in list of known hosts.
Index: dbpi.dsl
===================================================================
RCS file: /cvsroot/docbook/dsssl/html/dbpi.dsl,v
retrieving revision 1.1
diff -u -u -r1.1 dbpi.dsl
--- dbpi.dsl	2 Apr 2001 21:40:27 -0000	1.1
+++ dbpi.dsl	28 Apr 2003 05:15:48 -0000
@@ -29,7 +29,8 @@
 (define (dbhtml-findvalue pi-field-list name)
   ;; pi-field-list is '(pitarget name1 value1 name2 value2 ...)
   (let loop ((slist (cdr pi-field-list)))
-    (if (null? slist)
+    (if (or (null? slist)
+            (not (pair? slist)))
 	#f
 	(if (string=? (car slist) name)
 	    (car (cdr slist))
=== Exit status: 1
=== cd /home/adam/debian/docbook-dsssl/dsssl/lib/
=== /usr/bin/cvs diff -u dblib.dsl

DSA host key for IP address '66.35.250.207' not in list of known hosts.
Index: dblib.dsl
===================================================================
RCS file: /cvsroot/docbook/dsssl/lib/dblib.dsl,v
retrieving revision 1.5
diff -u -u -r1.5 dblib.dsl
--- dblib.dsl	26 Apr 2003 21:09:36 -0000	1.5
+++ dblib.dsl	28 Apr 2003 05:16:02 -0000
@@ -1793,20 +1793,28 @@
 ;; ======================================================================
 
 (define (parse-pi-attribute pivalues #!optional (skip #f))
-  (let* ((equalpos (string-index pivalues "="))
-	 (name     (substring pivalues 0 equalpos))
-	 (quotchar (substring pivalues (+ equalpos 1) (+ equalpos 2)))
-	 (rest     (substring pivalues 
-			      (+ equalpos 2) 
-			      (string-length pivalues)))
-	 (quotpos  (string-index rest quotchar))
-	 (value    (substring rest 0 quotpos))
-	 (morevals (strip (substring rest 
-				     (+ quotpos 1) 
-				     (string-length rest)))))
-    (if skip
-	morevals
-	(list name value))))
+  (let ((equalpos (string-index pivalues "=")))
+    (if (< equalpos 1)
+	(let ((debug (string-append "attribute not in form 'name=\"value\"': "
+                                    pivalues)))
+	  #f)
+	(let* ((name	 (substring pivalues 0 equalpos))
+	       (rest	 (substring pivalues (+ equalpos 1) (string-length pivalues)))
+               ;; location of the 2nd double quote
+               (quotpos  (string-index (substring rest 1 (string-length rest)) 
+                                       "\""))
+               (value    (strip (substring rest 0 (if (> quotpos 0)
+                                                      quotpos
+                                                      (string-length rest)))
+                                (list #\")))
+	       (morevals (if (> quotpos 0)
+                             (strip (substring rest
+                                               (+ quotpos 1)
+                                               (string-length rest)))
+                             #f)))
+	  (if skip
+	      morevals
+	      (list name value))))))
 
 (define (parse-skip-pi-attribute pivalues)
   (parse-pi-attribute pivalues #t))
@@ -1835,8 +1843,9 @@
 					   (+ spacepos 1)
 					   (string-length strippi)))))
 	  (let loop ((values pivalues) (result (list pitarget)))
-	    (if (string=? values "")
-		result
+	    (if (or (not values)
+                    (string=? values ""))
+                result
 		(loop (parse-skip-pi-attribute values)
 		      (append result (parse-pi-attribute values)))))))))
 
=== Exit status: 1

---

From: Yann Dirson <[email-masked]>
Date: Mon, 28 Apr 2003 11:09:20 +0200

> I believe I've fixed this bug in the DSSSL source.  I attach a patch.

Cool, thanks !

> is bad; now it silently skips over it.  Probably a warning would be

Well, AFAIUI there is no constraint on the contents of a PI in SGML -
it's just a matter of conventions.

Regards,
-- 
Yann Dirson    <[email-masked]> |    Why make M$-Bill richer & richer ?
Debian-related: <[email-masked]> |   Support Debian GNU/Linux:
Pro:    <[email-masked]> |  Freedom, Power, Stability, Gratuity
     http://ydirson.free.fr/        | Check <http://www.debian.org/>

---

From: Adam DiCarlo <[email-masked]>
Date: 29 Apr 2003 00:18:21 -0500

> it's just a matter of conventions.

Right, I was just saying ideally if there is a "<?dbhtml" directive we
can't figure out, i t might be nice to say so.

-- 
.....Adam Di [email-masked].....<URL:http://www.debian.org/>