diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2013-12-15 23:56:42 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2013-12-15 23:56:42 +0000 |
commit | df4b4fe716941b7152aa9d779f5c2e71c3acfaf7 (patch) | |
tree | 7f7f8cbcb5e80d482d4001b7cbc6983b97a3691e /mdoc_argv.c | |
parent | 27cd03954b92e571b0ffcfd50f45cbc141a10bb7 (diff) | |
download | mandoc-df4b4fe716941b7152aa9d779f5c2e71c3acfaf7.tar.gz mandoc-df4b4fe716941b7152aa9d779f5c2e71c3acfaf7.tar.zst mandoc-df4b4fe716941b7152aa9d779f5c2e71c3acfaf7.zip |
In quoted macro arguments, double quotes can be quoted by doubling them.
For a long time, we handle this in roff(7) and man(7) macros.
Now add correct handling for the mdoc(7) case, too.
Closely based on a patch by Tsugutomo dot ENAMI at jp dot sony dot com,
see http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=48438
received via Thomas Klausner (wiz@), slightly tweaked by me.
Diffstat (limited to 'mdoc_argv.c')
-rw-r--r-- | mdoc_argv.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/mdoc_argv.c b/mdoc_argv.c index 220260a6..b65a873b 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_argv.c,v 1.86 2012/11/18 00:05:35 schwarze Exp $ */ +/* $Id: mdoc_argv.c,v 1.87 2013/12/15 23:56:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2012 Ingo Schwarze <schwarze@openbsd.org> @@ -447,6 +447,7 @@ args(struct mdoc *mdoc, int line, int *pos, char *buf, enum argsflag fl, char **v) { char *p, *pp; + int pairs; enum margserr rc; if ('\0' == buf[*pos]) { @@ -540,6 +541,8 @@ args(struct mdoc *mdoc, int line, int *pos, /* * Process a quoted literal. A quote begins with a double-quote * and ends with a double-quote NOT preceded by a double-quote. + * Null-terminate the literal in place. + * Collapse pairs of quotes inside quoted literals. * Whitespace is NOT involved in literal termination. */ @@ -550,13 +553,22 @@ args(struct mdoc *mdoc, int line, int *pos, if (MDOC_PPHRASE & mdoc->flags) mdoc->flags |= MDOC_PHRASELIT; + pairs = 0; for ( ; buf[*pos]; (*pos)++) { + /* Move following text left after quoted quotes. */ + if (pairs) + buf[*pos - pairs] = buf[*pos]; if ('\"' != buf[*pos]) continue; + /* Unquoted quotes end quoted args. */ if ('\"' != buf[*pos + 1]) break; + /* Quoted quotes collapse. */ + pairs++; (*pos)++; } + if (pairs) + buf[*pos - pairs] = '\0'; if ('\0' == buf[*pos]) { if (MDOC_PPHRASE & mdoc->flags) |