Allows whitespace-only macro/procedure to be closed by \end (#7911)

* Added some passing macro definition parsing tests

* Added two failing tests to illustrate bug #3460

* Allow \end to end an whitespace only/empty macro definition. Fixes #3460

* Added some passing procedure definition tests

* Added two failing procedure tests to illustrate bug #3460

* Allow \end to end a whitespace only/empty procedure/function/widget definition. Fixes #3640

* Fixed wording of comment
This commit is contained in:
btheado 2024-01-24 06:32:58 -05:00 committed by GitHub
parent 100eaeff30
commit fb85e91f82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 168 additions and 6 deletions

View File

@ -49,11 +49,11 @@ exports.parse = function() {
if(this.match[3]) {
params = $tw.utils.parseParameterDefinition(this.match[4]);
}
// Is this a multiline definition?
// Is the remainder of the line blank after the parameter close paren?
var reEnd;
if(this.match[5]) {
// If so, the end of the body is marked with \end
reEnd = new RegExp("(\\r?\\n[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[2]) + ")?(?:$|\\r?\\n))","mg");
// If so, it is a multiline definition and the end of the body is marked with \end
reEnd = new RegExp("((:?^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[2]) + ")?(?:$|\\r?\\n))","mg");
} else {
// Otherwise, the end of the definition is marked by the end of the line
reEnd = /($|\r?\n)/mg;

View File

@ -54,11 +54,11 @@ exports.parse = function() {
paramMatch = reParam.exec(paramString);
}
}
// Is this a multiline definition?
// Is the remainder of the \define line blank after the parameter close paren?
var reEnd;
if(this.match[3]) {
// If so, the end of the body is marked with \end
reEnd = new RegExp("(\\r?\\n[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg");
// If so, it is a multiline definition and the end of the body is marked with \end
reEnd = new RegExp("((?:^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg");
} else {
// Otherwise, the end of the definition is marked by the end of the line
reEnd = /($|\r?\n)/mg;

View File

@ -0,0 +1,16 @@
title: Macros/EndInBody
description: \end line starting with non-whitespace is part of macro body
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\define hello()
hello \end
\end
Out: <<hello>>
+
title: ExpectedResult
<p>Out: hello \end</p>

View File

@ -0,0 +1,16 @@
title: Macros/IndentedEnd
description: \end line starting with whitespace ends a macro body
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\define hello()
hello \end
\end
Out: <<hello>>
+
title: ExpectedResult
<p>Out: hello \end</p>

View File

@ -0,0 +1,16 @@
title: Macros/MismatchedNamedEnd
description: Mismatched named end is part of the body
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\define hello()
\end goodbye
\end
Out: <<hello>>
+
title: ExpectedResult
<p>Out: \end goodbye</p>

View File

@ -0,0 +1,18 @@
title: Macros/WhitespaceOnlyWithEnd
description: The /end should be detected when macro definition contains only whitespace
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\define max()
\end
Nothing
\end
Out: <<max>>
+
title: ExpectedResult
<p>Nothing
\end</p><p>Out: </p>

View File

@ -0,0 +1,15 @@
title: Macros/WhitespaceOnlyWithEnd2
description: Line with \end can start with whitespace
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\define empty()
\end
Out: <<empty>>
+
title: ExpectedResult
<p>Out: </p>

View File

@ -0,0 +1,16 @@
title: Procedures/EndInBody
description: \end line starting with non-whitespace is part of procedure body
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\procedure hello()
hello \end
\end
Out: <<hello>>
+
title: ExpectedResult
<p>Out: hello \end</p>

View File

@ -0,0 +1,16 @@
title: Procedures/IndentedEnd
description: \end line starting with whitespace ends a procedure body
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\procedure hello()
hello \end
\end
Out: <<hello>>
+
title: ExpectedResult
<p>Out: hello \end</p>

View File

@ -0,0 +1,16 @@
title: Procedures/MismatchedNamedEnd
description: Mismatched named end is part of the body
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\procedure hello()
\end goodbye
\end
Out: <<hello>>
+
title: ExpectedResult
<p>Out: \end goodbye</p>

View File

@ -0,0 +1,18 @@
title: Procedures/WhitespaceOnlyWithEnd
description: The /end should be detected when procedure definition contains only whitespace
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\procedure max()
\end
Nothing
\end
Out: <<max>>
+
title: ExpectedResult
<p>Nothing
\end</p><p>Out: </p>

View File

@ -0,0 +1,15 @@
title: Procedures/WhitespaceOnlyWithEnd2
description: Line with \end can start with whitespace
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\procedure empty()
\end
Out: <<empty>>
+
title: ExpectedResult
<p>Out: </p>