diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-10-27 13:29:31 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-10-27 13:29:31 +0000 |
commit | bb1efa070ab2c0137a2b6f2c392c85ff187e02ee (patch) | |
tree | 758637c6a1262ba8ce8be3c99541d20a4aceb23b | |
parent | 0b50c5b9692186b93f1cf7144c054d773eb8788b (diff) |
Fix a regression in term.c rev. 1.89 reported by bentley@:
In UTF-8 output, do not print anything if mchars_spec2cp() returns 0.
In particular, this repairs handling of zero-width spaces (\&).
While here, let mchars_spec2cp() return 0xFFFD instead of -1
if the character is not found, simplifying the using code.
In HTML output, do not print obfuscated ASCII characters and
do not test for one-char escapes, mchars_spec2cp() already does that.
-rw-r--r-- | usr.bin/mandoc/chars.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/html.c | 11 | ||||
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 12 |
4 files changed, 15 insertions, 16 deletions
diff --git a/usr.bin/mandoc/chars.c b/usr.bin/mandoc/chars.c index 961769c80f0..00713a9cd30 100644 --- a/usr.bin/mandoc/chars.c +++ b/usr.bin/mandoc/chars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chars.c,v 1.31 2014/10/26 18:06:28 schwarze Exp $ */ +/* $OpenBSD: chars.c,v 1.32 2014/10/27 13:29:30 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -102,7 +102,7 @@ mchars_spec2cp(const struct mchars *arg, const char *p, size_t sz) const struct ln *ln; ln = find(arg, p, sz); - return(ln != NULL ? ln->unicode : sz == 1 ? *p : -1); + return(ln != NULL ? ln->unicode : sz == 1 ? *p : 0xFFFD); } char diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c index 219671ec597..47c59297012 100644 --- a/usr.bin/mandoc/html.c +++ b/usr.bin/mandoc/html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: html.c,v 1.47 2014/10/26 17:11:18 schwarze Exp $ */ +/* $OpenBSD: html.c,v 1.48 2014/10/27 13:29:30 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -455,11 +455,12 @@ print_encode(struct html *h, const char *p, int norecurse) break; case ESCAPE_SPECIAL: c = mchars_spec2cp(h->symtab, seq, len); - if (c > 0) + if (c <= 0) + break; + if (c < 0x20 || c > 0x7e) printf("&#%d;", c); - else if (-1 == c && 1 == len && - !print_escape(*seq)) - putchar((int)*seq); + else if ( ! print_escape(c)) + putchar(c); break; case ESCAPE_NOSPACE: if ('\0' == *p) diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index fb1e881826b..e4e0983ef39 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandocdb.c,v 1.121 2014/10/12 20:32:16 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.122 2014/10/27 13:29:30 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -1893,7 +1893,7 @@ render_key(struct mchars *mc, struct str *key) */ if (write_utf8) { - if (0 == (u = mchars_spec2cp(mc, seq, len))) + if ((u = mchars_spec2cp(mc, seq, len)) <= 0) continue; cpp = utfbuf; if (0 == (sz = utf8(u, utfbuf))) diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index b64b49095f3..33ed30422c4 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.89 2014/10/26 17:11:18 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.90 2014/10/27 13:29:30 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -466,9 +466,8 @@ term_word(struct termp *p, const char *word) encode(p, cp, ssz); } else { uc = mchars_spec2cp(p->symtab, seq, sz); - if (uc <= 0) - uc = 0xFFFD; - encode1(p, uc); + if (uc > 0) + encode1(p, uc); } break; case ESCAPE_FONTBOLD: @@ -703,9 +702,8 @@ term_strlen(const struct termp *p, const char *cp) } else { c = mchars_spec2cp(p->symtab, seq, ssz); - if (c <= 0) - c = 0xFFFD; - sz += cond_width(p, c, &skip); + if (c > 0) + sz += cond_width(p, c, &skip); } break; case ESCAPE_SKIPCHAR: |