summaryrefslogtreecommitdiffstats
path: root/html.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-12-27 21:41:05 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-12-27 21:41:05 +0000
commitd4699f958237b84a2f0dc8e3ed65b09a0069e821 (patch)
tree163d6b1776c5ac17851f8e7d0c3bdbb29f8affe5 /html.c
parent9375e42b897b6646ef05b8d8843932a7a80d1563 (diff)
downloadmandoc-d4699f958237b84a2f0dc8e3ed65b09a0069e821.tar.gz
In case an ID attribute is written in pieces, only protect the first
piece with a prepended 'x', not each piece, such that quoted and unquoted .Sh, .Ss, and .Sx arguments are compatible with each other. Fixing a bug reported by Nicolas Joly <njoly at NetBSD dot org>, avoiding a regression in my first patch as pointed out by njoly as well. "feel free to do so" kristaps@
Diffstat (limited to 'html.c')
-rw-r--r--html.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/html.c b/html.c
index 98ce7735..d82cec3c 100644
--- a/html.c
+++ b/html.c
@@ -771,20 +771,24 @@ html_idcat(char *dst, const char *src, int sz)
{
int ssz;
- assert(sz);
+ assert(sz > 2);
/* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */
- for ( ; *dst != '\0' && sz; dst++, sz--)
- /* Jump to end. */ ;
-
- assert(sz > 2);
-
/* We can't start with a number (bah). */
- *dst++ = 'x';
- *dst = '\0';
- sz--;
+ if ('#' == *dst) {
+ dst++;
+ sz--;
+ }
+ if ('\0' == *dst) {
+ *dst++ = 'x';
+ *dst = '\0';
+ sz--;
+ }
+
+ for ( ; *dst != '\0' && sz; dst++, sz--)
+ /* Jump to end. */ ;
for ( ; *src != '\0' && sz > 1; src++) {
ssz = snprintf(dst, (size_t)sz, "%.2x", *src);