Skip to content

Commit

Permalink
Merge pull request #50 from magicops/master
Browse files Browse the repository at this point in the history
Strings end with backslash bug fix, example "test\\"
  • Loading branch information
bijington authored Jul 16, 2019
2 parents f2efb79 + 351ae40 commit b43bec1
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Source/CSharp/Expressive/Expressive/ExpressionParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Expressive.Exceptions;
using Expressive.Exceptions;
using Expressive.Expressions;
using Expressive.Functions;
using Expressive.Functions.Conversion;
Expand Down Expand Up @@ -490,6 +490,14 @@ private static string CleanString(string input)
buffer[outIdx++] = '\'';
i++;
continue;
case '\"':
buffer[outIdx++] = '\"';
i++;
continue;
case '\\':
buffer[outIdx++] = '\\';
i++;
continue;
}
}
}
Expand Down Expand Up @@ -600,18 +608,28 @@ private static string GetString(string expression, int startIndex, char quoteCha
int index = startIndex;
bool foundEndingQuote = false;
var character = expression[index];
var previousCharacter = char.MinValue;
bool isEscape = false;

char[] escapableCharacters = new char[] { '\\', '"', '\'', 't', 'n', 'r' };

while (index < expression.Length && !foundEndingQuote)
{
if (index != startIndex &&
character == quoteCharacter &&
previousCharacter != '\\') // Make sure the escape character wasn't previously used.
!isEscape) // Make sure the escape character wasn't previously used.
{
foundEndingQuote = true;
}

previousCharacter = character;
if (isEscape && escapableCharacters.Contains(character))
{
isEscape = false;
}
else if (character == '\\' && !isEscape)
{
isEscape = true;
}

index++;

if (index == expression.Length)
Expand Down

0 comments on commit b43bec1

Please sign in to comment.