Skip to content

Commit 6e94c53

Browse files
committed
Fixed infinite loop when trying to parse an Atom, openend internals for use in the UI
1 parent b1a776e commit 6e94c53

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

Rubberduck.RegexAssistant/Atom.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Rubberduck.RegexAssistant
77
{
8-
internal interface IAtom : IDescribable
8+
public interface IAtom : IDescribable
99
{
1010
string Specifier { get; }
1111
}
@@ -101,9 +101,9 @@ public override int GetHashCode()
101101
}
102102
}
103103

104-
internal class Group : IAtom
104+
public class Group : IAtom
105105
{
106-
public static readonly string Pattern = @"(?<!\\)\((?<expression>.*)(?<!\\)\)";
106+
public static readonly string Pattern = @"(?<!\\)\((?<expression>.*(?<!\\))\)";
107107
private static readonly Regex Matcher = new Regex("^" + Pattern + "$");
108108

109109
private readonly IRegularExpression _subexpression;
@@ -119,6 +119,8 @@ public Group(string specifier) {
119119
_specifier = specifier;
120120
}
121121

122+
public IRegularExpression Subexpression { get { return _subexpression; } }
123+
122124
public string Specifier
123125
{
124126
get

Rubberduck.RegexAssistant/IRegularExpression.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface IRegularExpression : IDescribable
1313
IList<IRegularExpression> Subexpressions { get; }
1414
}
1515

16-
internal class ConcatenatedExpression : IRegularExpression
16+
public class ConcatenatedExpression : IRegularExpression
1717
{
1818
private readonly Quantifier _quantifier;
1919
private readonly IList<IRegularExpression> _subexpressions;
@@ -28,7 +28,8 @@ public string Description
2828
{
2929
get
3030
{
31-
return string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description));
31+
return AssistantResources.ExpressionDescription_ConcatenatedExpression;
32+
//return string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description));
3233
}
3334
}
3435

@@ -49,7 +50,7 @@ public IList<IRegularExpression> Subexpressions
4950
}
5051
}
5152

52-
internal class AlternativesExpression : IRegularExpression
53+
public class AlternativesExpression : IRegularExpression
5354
{
5455
private readonly Quantifier _quantifier;
5556
private readonly IList<IRegularExpression> _subexpressions;
@@ -64,7 +65,8 @@ public string Description
6465
{
6566
get
6667
{
67-
return AssistantResources.ExpressionDescription_AlternativesExpression + Environment.NewLine + string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description));
68+
return AssistantResources.ExpressionDescription_AlternativesExpression;
69+
// + Environment.NewLine + string.Join(Environment.NewLine, _subexpressions.Select(exp => exp.Description))
6870
}
6971
}
7072

@@ -85,7 +87,7 @@ public IList<IRegularExpression> Subexpressions
8587
}
8688
}
8789

88-
internal class SingleAtomExpression : IRegularExpression
90+
public class SingleAtomExpression : IRegularExpression
8991
{
9092
public readonly IAtom Atom;
9193
private readonly Quantifier _quantifier;
@@ -190,8 +192,11 @@ private static IRegularExpression ParseIntoConcatenatedExpression(ref string spe
190192
{
191193
List<IRegularExpression> subexpressions = new List<IRegularExpression>();
192194
string currentSpecifier = specifier;
193-
while (currentSpecifier.Length > 0)
195+
int oldSpecifierLength = currentSpecifier.Length + 1;
196+
while (currentSpecifier.Length > 0 && currentSpecifier.Length < oldSpecifierLength)
194197
{
198+
// Fugly hack for an error-return
199+
oldSpecifierLength = currentSpecifier.Length;
195200
IRegularExpression expression;
196201
// we actually have an AlternativesExpression, return the current status to Parse after updating the specifier
197202
if (currentSpecifier[0].Equals('|'))

Rubberduck.RegexAssistant/Pattern.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Rubberduck.RegexAssistant
55
{
66
public class Pattern : IDescribable
77
{
8-
IRegularExpression RootExpression;
8+
public IRegularExpression RootExpression;
99
MatcherFlags Flags;
1010

1111
private readonly bool _hasStartAnchor;
@@ -29,7 +29,7 @@ public Pattern(string expression, bool ignoreCase, bool global)
2929
_hasStartAnchor = expression[0].Equals('^');
3030

3131
int start = _hasStartAnchor ? 1 : 0;
32-
int end = (_hasEndAnchor ? 1 : 0) + start + 1;
32+
int end = (_hasEndAnchor ? 1 : 0) + start;
3333
RootExpression = RegularExpression.Parse(expression.Substring(start, expression.Length - end));
3434
_description = AssembleDescription();
3535
}

Rubberduck.RegexAssistant/i18n/AssistantResources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.RegexAssistant/i18n/AssistantResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189
<data name="ExpressionDescription_AlternativesExpression" xml:space="preserve">
190190
<value>Matches one of the following alternatives:</value>
191191
</data>
192+
<data name="ExpressionDescription_ConcatenatedExpression" xml:space="preserve">
193+
<value>Matches the exact sequence given as follows:</value>
194+
</data>
192195
<data name="PatternDescription_AnchorEnd" xml:space="preserve">
193196
<value>$ ensures all characters of the string are consumed</value>
194197
</data>

0 commit comments

Comments
 (0)