From a629f7c1e6958d7f3fd35692d5c0df8697a743a0 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 27 Dec 2010 21:41:05 +0000 Subject: 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 , avoiding a regression in my first patch as pointed out by njoly as well. "feel free to do so" kristaps@ --- html.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/html.c b/html.c index ac05a6fc..70403ff7 100644 --- a/html.c +++ b/html.c @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.123 2010/12/24 14:14:00 kristaps Exp $ */ +/* $Id: html.c,v 1.124 2010/12/27 21:41:05 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -771,20 +771,24 @@ html_idcat(char *dst, const char *src, int sz) { int ssz; - assert(sz); + assert(sz > 2); /* Cf. . */ - 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); -- cgit v1.2.3-56-ge451