Skip to content

Commit

Permalink
Issue 15475: ddoc should not escape unbalanced parens in code blocks.
Browse files Browse the repository at this point in the history
Add test case.
  • Loading branch information
H. S. Teoh committed Mar 8, 2016
1 parent 5c569a9 commit 70c53a5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/doc.d
Expand Up @@ -657,25 +657,30 @@ extern (C++) void escapeDdocString(OutBuffer* buf, size_t start)
extern (C++) void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start)
{
uint par_open = 0;
bool inCode = 0;
for (size_t u = start; u < buf.offset; u++)
{
char c = buf.data[u];
switch (c)
{
case '(':
par_open++;
if (!inCode)
par_open++;
break;
case ')':
if (par_open == 0)
if (!inCode)
{
//stray ')'
warning(loc, "Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.");
buf.remove(u, 1); //remove the )
buf.insert(u, cast(const(char)*)"$(RPAREN)", 9); //insert this instead
u += 8; //skip over newly inserted macro
if (par_open == 0)
{
//stray ')'
warning(loc, "Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.");
buf.remove(u, 1); //remove the )
buf.insert(u, cast(const(char)*)"$(RPAREN)", 9); //insert this instead
u += 8; //skip over newly inserted macro
}
else
par_open--;
}
else
par_open--;
break;
version (none)
{
Expand All @@ -686,6 +691,18 @@ extern (C++) void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start)
loc.linnum++;
break;
}
case '-':
// Issue 15465: don't try to escape unbalanced parens inside code
// blocks.
int numdash = 0;
while (u < buf.offset && buf.data[u] == '-')
{
numdash++;
u++;
}
if (numdash >= 3)
inCode = !inCode;
break;
default:
break;
}
Expand Down
12 changes: 12 additions & 0 deletions test/compilable/ddoc15475.d
@@ -0,0 +1,12 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o-
// POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 15475

/**
My module
----
// Computes the interval [x,y)
auto interval = computeInterval(x, y);
----
*/
module ddoc15475;
14 changes: 14 additions & 0 deletions test/compilable/extra-files/ddoc15475.html
@@ -0,0 +1,14 @@
<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>ddoc15475</title>
</head><body>
<h1>ddoc15475</h1>
My module
<pre class="d_code"> <font color=green>// Computes the interval [x,y)
</font> <font color=blue>auto</font> interval = computeInterval(x, y);
</pre>
<br><br>


<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>

0 comments on commit 70c53a5

Please sign in to comment.