From patchwork Mon Oct 12 18:09:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 11833537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E639C43467 for ; Mon, 12 Oct 2020 18:09:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F01A82087D for ; Mon, 12 Oct 2020 18:09:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lQYVhnam" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404129AbgJLSJh (ORCPT ); Mon, 12 Oct 2020 14:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404102AbgJLSJh (ORCPT ); Mon, 12 Oct 2020 14:09:37 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 150C7C0613D1 for ; Mon, 12 Oct 2020 11:09:33 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id d3so18438027wma.4 for ; Mon, 12 Oct 2020 11:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=StxlXjv+IFLEsxEMFtiDzQdyEg08Qv5k6leyyRrktjE=; b=lQYVhnam4dm/smmZ8dXpgHhlryyhKclnMPsLwslmsjUwO13dT9oJIO+zDdpw/bm3vT jta6Ba8gBHOD05J9EwyNMDmSvS/M4U+cTmAV7AXwbclkfFH/Lbg9uj2zdKEuxt7oBQ6P +GE3tjnF9C9Nqi1I80C7Ns54FGaWsxGhCQTxN7NRWYFIOUvoAwJ/bFrHG9NP9HSDJv0D 4O82M8V3z5utp9ezK1UDNSpyljiver2831nyvSF7u3dUvUnn+cPcZs0K5YuDefPMv2kQ m/bMQSw0j+TR6es/9N2oz5dKkTq1pNqQPWCQVUZVE6ojo2dmLz+vBNb580uBLwX4q613 dSuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=StxlXjv+IFLEsxEMFtiDzQdyEg08Qv5k6leyyRrktjE=; b=QUTUEzkc52/5EeJa40InsGgFbTSCMA5ZLNEYW/CPswNm8LT/E4XCKbqaXmrCcrtGxt lFBaXgq6PlbMW7mPPnNzAaMTBKOGZVVO8dfsLyrfeFQXFbpCk6JZUSpYyrv3XeMRTbqs coiqckoNSZvsdlzQuGu5VlQ+ahSRUjyLI6LZL5DviPVSQV+DjwiBueto4sdhEyGV6vge 5szxW3gBHXD217kdcjnzesLzqIv2j0AKr9f9BKXHNe/yrl7JUlxEzD+2Ou7eITIkSjR5 4MWuCQUkBt4pjNhi7t7CCzRBrUFqsiZkJ9IvRTFCCTUHR/EJgyJPRjFfR0GdPToiTHfY Ghag== X-Gm-Message-State: AOAM533J+8gh0wWD20DbGzJFzDYw4UuLx8IkjzngQFiYKFa6Luo+sUEL 3FyJsFvTjoflx3GXZVts8r+6wRXepRU= X-Google-Smtp-Source: ABdhPJwtBPf7AK1IJ7jbDNYjSZEoZ7RKSUlBVSOa3pltXO6mlLaw9tXJBBrWuwHGEK5vyikCQrMSnQ== X-Received: by 2002:a05:600c:2297:: with SMTP id 23mr12401174wmf.104.1602526171525; Mon, 12 Oct 2020 11:09:31 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w5sm24387338wmg.42.2020.10.12.11.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 11:09:31 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 12 Oct 2020 18:09:27 +0000 Subject: [PATCH v3 1/3] t: add lib-crlf-messages.sh for messages containing CRLF Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Michael J Gruber , Matthieu Moy , John Keeping , Karthik Nayak , Jeff King , Alex Henrie , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain A following commit will fix a bug in the ref-filter API that causes commit and tag messages containing CRLF to be incorrectly parsed and displayed. Add a test library (t/lib-crlf-messages.sh) that creates refs with such commit messages, so that we can easily test that this bug does not appear in other commands in the future. The function `test_crlf_subject_body_and_contents` can be used to test that the `--format` option of `branch`, `tag`, `for-each-ref` and `log` correctly displays the subject, body and raw content of commits and tag messages. The commits are created using `commit-tree` such that the current branch in the test repository is not affected when `test_create_crlf_refs` is called in a test. This is done so that the CRLF tests can be inserted anywhere in a test script, where it makes sense to do so, without having to potentially modify further tests that depend on output that would be modified if the current branch gained new commits. Signed-off-by: Philippe Blain --- t/lib-crlf-messages.sh | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 t/lib-crlf-messages.sh diff --git a/t/lib-crlf-messages.sh b/t/lib-crlf-messages.sh new file mode 100644 index 0000000000..10a2b57280 --- /dev/null +++ b/t/lib-crlf-messages.sh @@ -0,0 +1,90 @@ +# Setup refs with commit and tag messages containing CRLF + +LIB_CRLF_BRANCHES="" + +create_crlf_ref () { + message="$1" && + subject="$2" && + body="$3" && + branch="$4" && + printf "${message}" >.crlf-message-${branch}.txt && + printf "${subject}" >.crlf-subject-${branch}.txt && + printf "${body}" >.crlf-body-${branch}.txt && + LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}" + test_tick && + hash=$(git commit-tree HEAD^{tree} -p HEAD -F .crlf-message-${branch}.txt) && + git branch ${branch} ${hash} && + git tag tag-${branch} ${branch} -F .crlf-message-${branch}.txt --cleanup=verbatim +} + +create_crlf_refs () { + message="Subject first line\r\n\r\nBody first line\r\nBody second line\r\n" && + body="Body first line\r\nBody second line\r\n" && + subject="Subject first line" && + branch="crlf" && + create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" && + message="Subject first line\r\n\r\n\r\nBody first line\r\nBody second line\r\n" && + branch="crlf-empty-lines-after-subject" && + create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" && + message="Subject first line\r\nSubject second line\r\n\r\nBody first line\r\nBody second line\r\n" && + subject="Subject first line Subject second line" && + branch="crlf-two-line-subject" && + create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" && + message="Subject first line\r\nSubject second line" && + subject="Subject first line Subject second line" && + body="" && + branch="crlf-two-line-subject-no-body" && + create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" && + message="Subject first line\r\nSubject second line\r\n" && + branch="crlf-two-line-subject-no-body-trailing-newline" && + create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" && + message="Subject first line\r\nSubject second line\r\n\r" && + branch="crlf-two-line-subject-no-body-trailing-newline2" && + create_crlf_ref "${message}" "${subject}" "${body}" "${branch}" +} + +test_create_crlf_refs () { + test_expect_success 'setup refs with CRLF commit messages' ' + create_crlf_refs + ' +} + +cleanup_crlf_refs () { + for branch in ${LIB_CRLF_BRANCHES}; do + git branch -D ${branch} && + git tag -d tag-${branch} && + rm .crlf-message-${branch}.txt && + rm .crlf-subject-${branch}.txt && + rm .crlf-body-${branch}.txt + done +} + +test_cleanup_crlf_refs () { + test_expect_success 'cleanup refs with CRLF commit messages' ' + cleanup_crlf_refs + ' +} + +test_crlf_subject_body_and_contents() { + command_and_args="$@" && + command=$1 && + if [ ${command} = "branch" ] || [ ${command} = "for-each-ref" ] || [ ${command} = "tag" ]; then + atoms="(contents:subject) (contents:body) (contents)" + elif [ ${command} = "log" ] || [ ${command} = "show" ]; then + atoms="s b B" + fi && + files="subject body message" && + while [ -n "${atoms}" ]; do + set ${atoms} && atom=$1 && shift && atoms="$*" && + set ${files} && file=$1 && shift && files="$*" && + test_expect_success "${command}: --format='%${atom}' works with CRLF input" " + rm -f expect && + for ref in ${LIB_CRLF_BRANCHES}; do + cat .crlf-${file}-\"\${ref}\".txt >>expect && + printf \"\n\" >>expect + done && + git $command_and_args --format=\"%${atom}\" >actual && + test_cmp expect actual + " + done +} From patchwork Thu Oct 22 03:01:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 11850171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04BD8C55178 for ; Thu, 22 Oct 2020 03:01:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85B87223C7 for ; Thu, 22 Oct 2020 03:01:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oL+Dy0nQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2895250AbgJVDBY (ORCPT ); Wed, 21 Oct 2020 23:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2895247AbgJVDBY (ORCPT ); Wed, 21 Oct 2020 23:01:24 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D69AC0613CF for ; Wed, 21 Oct 2020 20:01:24 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id d78so157724wmd.3 for ; Wed, 21 Oct 2020 20:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1Ef/8ZxkLtSCBI23VBtlkS9reXhwctv2fuHH6MwFNuo=; b=oL+Dy0nQ9fTv1HeKYWnLbm0L0kxPunazOFXdBbq03bngS/9Y9NR/YVj6ou812i9QJM 4dZ/UHIt0SPFLtfeBUCQOK+UCHVvMAcGxRqJZ4ekeIppkmJXB8Df86xGqzrD6RXH9GZo 5mPgWCUSPhYVHjfTlUN17vv9K8JBIAuHtamlHYbMecDyI16cm7TuyDUbH2vPugJUDLDW GdNUwo59j8yqx27NethgwtyqDQM3mEjCxhIM4QW0/+ssl99A4a0PmMlA2V5rsE8MZtHi Wwf/Zw0g5fjUIA+pFWQgUhHnPiXQeF+k9tycLbg2Zg+elmKn4JVIHh4eO7RWDV4U41D6 VKoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1Ef/8ZxkLtSCBI23VBtlkS9reXhwctv2fuHH6MwFNuo=; b=mjEzpksQ3mgTiLmOHfV7B0oWHox/8r3NOfVeOgFibNGNOpBb8fVexIPpkemjPFF5+Q o5ejvtUGJsuXQCh6cZoYzh1it3Yu2FbpqhVs+jv6lhL+l8kgjxqfjNnoJB8BMfQ/9R1o 4zFIx2rr4vDkI1/5s2SXXW0coDuRyyRCReMskSI+tDr1ei0YAlQTDROoSxYOlaGaNNA9 oGQSZdPfNz504zgsgLajL9AvBLqkDeQQQ4M+AzIeeKpS+YBly3fq4/eZcGyBaJ/PBos9 OE8dxyZzyKkduE7VS6mRnPDHs3pT2Yi1a3BqJmGYIRumnvodBQqGtAZP8x7uJHPp92ni nS5w== X-Gm-Message-State: AOAM530dLPdEQJx4AOGTXR2boAd+bbOIlStarksnITjFi9ZWlL6/T3Yh cAVz/biqpqVXStftAza9JQNLqTSw66M= X-Google-Smtp-Source: ABdhPJwsagbQTECvnM1rEkrIMWK+JoJl3HfM4b4WeMNJxdfo/8khtG9c7e7zedBdyxKKSANmuReqiQ== X-Received: by 2002:a7b:cb13:: with SMTP id u19mr375603wmj.89.1603335682697; Wed, 21 Oct 2020 20:01:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t12sm544188wrm.25.2020.10.21.20.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 20:01:22 -0700 (PDT) Message-Id: <75a87887be5d8364b37655f0588ed98a52de92bc.1603335680.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Oct 2020 03:01:19 +0000 Subject: [PATCH v4 2/2] log, show: add tests for messages containing CRLF Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Michael J Gruber , Matthieu Moy , John Keeping , Karthik Nayak , Jeff King , Alex Henrie , Eric Sunshine , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain A previous commit fixed a bug in ref-filter.c causing messages containing CRLF to be incorrectly parsed and displayed. Add tests to also check that `git log` and `git show` correctly handle such messages, to prevent futur regressions if these commands are refactored to use the ref-filter API. Signed-off-by: Philippe Blain --- t/t3920-crlf-messages.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/t/t3920-crlf-messages.sh b/t/t3920-crlf-messages.sh index 3f0ce02c3f..b6e09be412 100755 --- a/t/t3920-crlf-messages.sh +++ b/t/t3920-crlf-messages.sh @@ -105,4 +105,22 @@ test_crlf_subject_body_and_contents tag --list tag-crlf* test_crlf_subject_body_and_contents for-each-ref refs/heads/crlf* +test_expect_success 'log: --oneline works with messages using CRLF' ' + for branch in $LIB_CRLF_BRANCHES + do + cat .crlf-subject-${branch}.txt >expect && + printf "\n" >>expect && + git log --oneline -1 ${branch} >tmp-branch && + git log --oneline -1 tag-${branch} >tmp-tag && + cut -d" " -f2- actual-branch && + cut -d" " -f2- actual-tag && + test_cmp expect actual-branch && + test_cmp expect actual-tag + done +' + +test_crlf_subject_body_and_contents log --all --reverse --grep Subject + +test_crlf_subject_body_and_contents show $LIB_CRLF_BRANCHES + test_done