aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/man_validate.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-07-20 14:56:42 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-07-20 14:56:42 +0000
commit28f89d13b7d6b04d99517c6e31655ddfbd3ea541 (patch)
treeeddf064f205df6769af821586c16ae6b774b25fc /man_validate.c
parentf62e3bc028493beff5eb1eab67d8f60670958e0b (diff)
downloadmandoc-28f89d13b7d6b04d99517c6e31655ddfbd3ea541.tar.gz
mandoc-28f89d13b7d6b04d99517c6e31655ddfbd3ea541.tar.zst
mandoc-28f89d13b7d6b04d99517c6e31655ddfbd3ea541.zip
Strip non-graphable input characters from input. The manuals
specifically say that this is not allowed, and were it allowed, output would be inconsistent across output media (-Tps will puke, non-your-charset terminals will puke, etc.). With this done, simplify check_text() to only check escapes and for tabs. Add in a new tab warning, too.
Diffstat (limited to 'man_validate.c')
-rw-r--r--man_validate.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/man_validate.c b/man_validate.c
index 48469495..16561b2b 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.45 2010/06/28 14:39:17 kristaps Exp $ */
+/* $Id: man_validate.c,v 1.46 2010/07/20 14:56:42 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -26,6 +26,7 @@
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
#include "mandoc.h"
#include "libman.h"
@@ -206,32 +207,37 @@ check_text(CHKARGS)
{
char *p;
int pos, c;
-
- assert(n->string);
+ size_t sz;
for (p = n->string, pos = n->pos + 1; *p; p++, pos++) {
- if ('\\' == *p) {
- c = mandoc_special(p);
- if (c) {
- p += c - 1;
- pos += c - 1;
- continue;
- }
+ sz = strcspn(p, "\t\\");
+ p += (int)sz;
+
+ if ('\0' == *p)
+ break;
+
+ pos += (int)sz;
- c = man_pmsg(m, n->line, pos, MANDOCERR_BADESCAPE);
- if ( ! (MAN_IGN_ESCAPE & m->pflags) && ! c)
- return(c);
+ if ('\t' == *p) {
+ if (MAN_LITERAL & m->flags)
+ continue;
+ if (man_pmsg(m, n->line, pos, MANDOCERR_BADTAB))
+ continue;
+ return(0);
}
- /*
- * FIXME: we absolutely cannot let \b get through or it
- * will destroy some assumptions in terms of format.
- */
+ /* Check the special character. */
- if ('\t' == *p || isprint((u_char)*p) || ASCII_HYPH == *p)
+ c = mandoc_special(p);
+ if (c) {
+ p += c - 1;
+ pos += c - 1;
continue;
- if ( ! man_pmsg(m, n->line, pos, MANDOCERR_BADCHAR))
- return(0);
+ }
+
+ c = man_pmsg(m, n->line, pos, MANDOCERR_BADESCAPE);
+ if ( ! (MAN_IGN_ESCAPE & m->pflags) && ! c)
+ return(c);
}
return(1);