From owner-svn-src-all@FreeBSD.ORG Fri Jun 19 22:09:55 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 80957106564A; Fri, 19 Jun 2009 22:09:55 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E6328FC0A; Fri, 19 Jun 2009 22:09:55 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5JM9ttV056727; Fri, 19 Jun 2009 22:09:55 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5JM9tVK056725; Fri, 19 Jun 2009 22:09:55 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <200906192209.n5JM9tVK056725@svn.freebsd.org> From: Jilles Tjoelker Date: Fri, 19 Jun 2009 22:09:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194516 - head/bin/sh X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Jun 2009 22:09:56 -0000 Author: jilles Date: Fri Jun 19 22:09:55 2009 New Revision: 194516 URL: http://svn.freebsd.org/changeset/base/194516 Log: Fix some issues with quoted output and shorten it in some cases. Output quoted suitable for re-input to the shell occurs in various cases such as 'set', 'trap'. Bugfix: *, ? and [ must be quoted (except sole [) Bugfix: ~ and # must be quoted (really only sometimes, but keep it simple) Bugfix: space, tab and newline must always be quoted Shortening: other IFS characters do not need quoting Bugfix: send to correct output file, not hard-coded stdout Shortening: avoid unnecessary '' with \' Approved by: ed (mentor) Modified: head/bin/sh/output.c Modified: head/bin/sh/output.c ============================================================================== --- head/bin/sh/output.c Fri Jun 19 21:14:39 2009 (r194515) +++ head/bin/sh/output.c Fri Jun 19 22:09:55 2009 (r194516) @@ -133,32 +133,38 @@ void outqstr(const char *p, struct output *file) { char ch; + int inquotes; if (p[0] == '\0') { outstr("''", file); return; } - if (p[strcspn(p, "|&;<>()$`\\\"'")] == '\0' && (!ifsset() || - p[strcspn(p, ifsval())] == '\0')) { + /* Caller will handle '=' if necessary */ + if (p[strcspn(p, "|&;<>()$`\\\"' \t\n*?[~#")] == '\0' || + strcmp(p, "[") == 0) { outstr(p, file); return; } - out1c('\''); + inquotes = 0; while ((ch = *p++) != '\0') { switch (ch) { case '\'': - /* - * Can't quote single quotes inside single quotes; - * close them, write escaped single quote, open again. - */ - outstr("'\\''", file); + /* Can't quote single quotes inside single quotes. */ + if (inquotes) + outc('\'', file); + inquotes = 0; + outstr("\\'", file); break; default: + if (!inquotes) + outc('\'', file); + inquotes = 1; outc(ch, file); } } - out1c('\''); + if (inquotes) + outc('\'', file); } STATIC char out_junk[16];