From 3a31fe68efcf80888294a1d3d33751d266d4de07 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 5 Jul 2021 14:45:07 -0700
Subject: [PATCH] Add command test for #7394.

And fix a small bug in handling of citations in notes, which
led to commas at the end of sentences in some cases.
---
 src/Text/Pandoc/Citeproc.hs |  1 +
 test/command/7394.md        | 85 +++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 test/command/7394.md

diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
index 6e2d9ce7e..246f54516 100644
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -612,6 +612,7 @@ deNote (Note bs) =
   noteInParens x = [x]
 
   noteAfterComma needsPer (Span ("",["csl-note"],[]) ils)
+    | not (null ils)
        = Str "," : Space :
          if needsPer
             then ils
diff --git a/test/command/7394.md b/test/command/7394.md
new file mode 100644
index 000000000..d6eb769b9
--- /dev/null
+++ b/test/command/7394.md
@@ -0,0 +1,85 @@
+```
+% pandoc -f markdown -t plain --citeproc
+---
+csl: command/chicago-fullnote-bibliography.csl
+references:
+- author:
+  - family: Wandt
+    given: Manfred
+  edition: 6
+  id: wandt2014ges-sv
+  issued: 2014
+  publisher: Franz Vahlen
+  publisher-place: München
+  title: Gesetzliche schuldverhältnisse
+  title-short: Gesetzl SV
+  type: book
+- author:
+  - family: Smith
+    given: Zenda
+  edition: 6
+  id: smith2015
+  issued: 2015
+  publisher: Macmillan
+  publisher-place: New York
+  title: A verb and a noun
+  type: book
+---
+
+Hi^[@wandt2014ges-sv.].
+
+Hi^[[@wandt2014ges-sv].].
+
+Hi^[[See also @wandt2014ges-sv].].
+
+Hi^[See also @wandt2014ges-sv.].
+
+Hi^[@wandt2014ges-sv [@smith2015].].
+
+Hi^[[@wandt2014ges-sv; @smith2015].].
+
+Hi [@wandt2014ges-sv].
+
+Hi [see also @wandt2014ges-sv].
+
+^D
+Hi[1].
+
+Hi[2].
+
+Hi[3].
+
+Hi[4].
+
+Hi[5].
+
+Hi[6].
+
+Hi.[7]
+
+Hi.[8]
+
+Smith, Zenda. A Verb and a Noun. 6th ed. New York: Macmillan, 2015.
+
+Wandt, Manfred. Gesetzliche Schuldverhältnisse. 6th ed. München: Franz
+Vahlen, 2014.
+
+[1] Manfred Wandt, Gesetzliche Schuldverhältnisse, 6th ed. (München:
+Franz Vahlen, 2014).
+
+[2] Wandt.
+
+[3] See also Wandt.
+
+[4] See also Wandt.
+
+[5] Wandt, Zenda Smith, A Verb and a Noun, 6th ed. (New York: Macmillan,
+2015).
+
+[6] Wandt, Gesetzl SV; Smith, A Verb and a Noun.
+
+[7] Wandt, Gesetzl SV.
+
+[8] See also Wandt.
+```
+