Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/mdocml/dist Fix handling of nested double quotes.



details:   https://anonhg.NetBSD.org/src/rev/362cfc6954f0
branches:  trunk
changeset: 325301:362cfc6954f0
user:      wiz <wiz%NetBSD.org@localhost>
date:      Tue Dec 17 09:28:10 2013 +0000

description:
Fix handling of nested double quotes.

>From Ingo Schwarze <schwarze%usta.de@localhost> based on patch by enami@
in PR 48438.

diffstat:

 external/bsd/mdocml/dist/mdoc_argv.c |  12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diffs (43 lines):

diff -r 27711efbb16b -r 362cfc6954f0 external/bsd/mdocml/dist/mdoc_argv.c
--- a/external/bsd/mdocml/dist/mdoc_argv.c      Tue Dec 17 08:46:37 2013 +0000
+++ b/external/bsd/mdocml/dist/mdoc_argv.c      Tue Dec 17 09:28:10 2013 +0000
@@ -453,6 +453,7 @@
                char *buf, enum argsflag fl, char **v)
 {
        char            *p, *pp;
+       int              pairs;
        enum margserr    rc;
 
        if ('\0' == buf[*pos]) {
@@ -546,6 +547,8 @@
        /* 
         * 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.
         */
 
@@ -556,13 +559,22 @@
                if (MDOC_PPHRASE & m->flags)
                        m->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 & m->flags)



Home | Main Index | Thread Index | Old Index