From owner-dev-commits-src-all@freebsd.org Mon Jun 7 13:55:49 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4622C64E4E6; Mon, 7 Jun 2021 13:55:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FzFJP0vZDz3CWG; Mon, 7 Jun 2021 13:55:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 079D716BA4; Mon, 7 Jun 2021 13:55:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 157Dtm00091792; Mon, 7 Jun 2021 13:55:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 157DtmJ0091791; Mon, 7 Jun 2021 13:55:48 GMT (envelope-from git) Date: Mon, 7 Jun 2021 13:55:48 GMT Message-Id: <202106071355.157DtmJ0091791@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?B?U3RlZmFuIEXDn2Vy?= Subject: git: 35b8fd0b699a - main - usr.bin/calendar: do not treat // in text as comment MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 35b8fd0b699a20f71d5636069347b243eb336979 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jun 2021 13:55:49 -0000 The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=35b8fd0b699a20f71d5636069347b243eb336979 commit 35b8fd0b699a20f71d5636069347b243eb336979 Author: Stefan Eßer AuthorDate: 2021-06-07 13:46:24 +0000 Commit: Stefan Eßer CommitDate: 2021-06-07 13:55:23 +0000 usr.bin/calendar: do not treat // in text as comment The C++-style comment marker "//" has been added with the rewrite of the preprocessor features. Since this character sequence occurs in ULRS, the reminder of the URL was considered a comment and stripped from the calendar line. Change parsing of "//" to only start a comment at the begin of a line or when preceeded by a white-space character. PR: 256455 Reported by: Philippe Michel (philippe.michel7 at free.fr) MFC after: 3 days --- usr.bin/calendar/io.c | 22 ++++++++++++++-------- usr.bin/calendar/tests/calendar.comment | 3 ++- usr.bin/calendar/tests/regress.comment.out | 2 ++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index 24966399c179..5afcb1a33314 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -405,7 +405,7 @@ cal_parse(FILE *in, FILE *out) { char *mylocale = NULL; char *line = NULL; - char *buf; + char *buf, *bufp; size_t linecap = 0; ssize_t linelen; ssize_t l; @@ -443,21 +443,27 @@ cal_parse(FILE *in, FILE *out) } } if (!incomment) { + bufp = buf; do { - c = strstr(buf, "//"); - cc = strstr(buf, "/*"); + c = strstr(bufp, "//"); + cc = strstr(bufp, "/*"); if (c != NULL && (cc == NULL || c - cc < 0)) { - /* single line comment */ - *c = '\0'; - linelen = c - buf; - break; + bufp = c + 2; + /* ignore "//" within string to allow it in an URL */ + if (c == buf || isspace(c[-1])) { + /* single line comment */ + *c = '\0'; + linelen = c - buf; + break; + } } else if (cc != NULL) { c = strstr(cc + 2, "*/"); - if (c != NULL) { + if (c != NULL) { // 'a /* b */ c' -- cc=2, c=7+2 /* multi-line comment ending on same line */ c += 2; memmove(cc, c, buf + linelen + 1 - c); linelen -= c - cc; + bufp = cc; } else { /* multi-line comment */ *cc = '\0'; diff --git a/usr.bin/calendar/tests/calendar.comment b/usr.bin/calendar/tests/calendar.comment index 6af037ec7e9d..837e5af9e89e 100644 --- a/usr.bin/calendar/tests/calendar.comment +++ b/usr.bin/calendar/tests/calendar.comment @@ -7,4 +7,5 @@ 1/* comment */ 6 jan 6 1 7 jan 7 // /* comment */ comment 1 1/* comment */1 jan /* comment */11 // comment - +1 12 http://localhost.local/ +1 13 http://localhost.local/ // URL with additional comment diff --git a/usr.bin/calendar/tests/regress.comment.out b/usr.bin/calendar/tests/regress.comment.out index 1ba3d8cc640e..fb58fd29ff05 100644 --- a/usr.bin/calendar/tests/regress.comment.out +++ b/usr.bin/calendar/tests/regress.comment.out @@ -6,3 +6,5 @@ Jan 5 jan 5 Jan 6 jan 6 Jan 7 jan 7 Jan 11 jan 11 +Jan 12 http://localhost.local/ +Jan 13 http://localhost.local/