Skip to content
This repository was archived by the owner on Mar 1, 2022. It is now read-only.

Commit ef3cd0a

Browse files
committed
fix unescapeString call
the argument should already be a string literal, but I couldn't reproduce the issue yet. So now in release mode there is a warning when the contract would fail and in debug mode a regular exception is thrown. The malformed string literal should be fixed with unescape string, but it might just be memory corruption as well.
1 parent d9c2305 commit ef3cd0a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

source/workspaced/dparseext.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module workspaced.dparseext;
22

33
import std.algorithm;
44
import std.array;
5+
import std.experimental.logger;
56
import std.string;
67

78
import dparse.ast;
@@ -281,7 +282,7 @@ in (expr !is null)
281282
/// ditto
282283
string evaluateExpressionString(const Token token)
283284
{
284-
import dparse.strings : unescapeString;
285+
import dparse.strings : unescapeString, isStringLiteral;
285286

286287
switch (token.type)
287288
{
@@ -306,7 +307,22 @@ string evaluateExpressionString(const Token token)
306307
case tok!"stringLiteral":
307308
case tok!"wstringLiteral":
308309
case tok!"dstringLiteral":
309-
ret ~= unescapeString(t.text);
310+
if (t.text.isStringLiteral)
311+
{
312+
ret ~= unescapeString(t.text);
313+
}
314+
else
315+
{
316+
debug
317+
{
318+
throw new Exception("Invalid stringLiteral in stringLiteral token: `" ~ t.text ~ '`');
319+
}
320+
else
321+
{
322+
warningf("Invalid stringLiteral in stringLiteral token: `%s`", t.text);
323+
return str;
324+
}
325+
}
310326
break;
311327
default:
312328
// unexpected token, return input because it might already be

0 commit comments

Comments
 (0)