Skip to content

Commit

Permalink
bit mask resize bug in StringSearcher. Thanks CrazyWonton
Browse files Browse the repository at this point in the history
  • Loading branch information
mtimmerm committed Apr 24, 2019
1 parent ad0acd6 commit 59ee0d2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/nobigsoftware/dfalex/StringSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public StringMatchIterator<MATCHRESULT> searchString(String src)
{
//need a longer array
int toadd = Math.max(maskStartPos-pos, maskArray.length<<5);
toadd = (toadd|31)>>5; //bits to ints
toadd = (toadd+31)>>5; //bits to ints
int[] newMask = new int[maskArray.length + toadd];
for (int i=0;i<maskArray.length;++i)
{
Expand Down
22 changes: 22 additions & 0 deletions test/com/nobigsoftware/dfalex/SearcherTestInput2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>

<name>aalto-xml</name>
<javac.target.version>${java.version}</javac.target.version>
<exclude>**/*$*</exclude>
<exclude>failing/*.java</exclude>
</excludes>
<reportFormat>${surefire.format}</reportFormat>
<useFile>${surefire.usefile}</useFile>
<forkMode>${surefire.fork.mode}</forkMode>
<childDelegation>false</childDelegation>
<argLine>${surefire.fork.vmargs}</argLine>
<systemProperties>
<property>
<name>java.awt.headless</name>
<value>${java.awt.headless}</value>
</property>
<property>
<name>surefire.fork.vmargs</name>
<value>${surefire.fork.vmargs}</value>
12 changes: 12 additions & 0 deletions test/com/nobigsoftware/dfalex/StringSearcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public void test() throws Exception
Assert.assertEquals(want, have);
}

@Test
public void crazyWontonTest() throws Exception
{
SearchAndReplaceBuilder builder = new SearchAndReplaceBuilder();
builder.addReplacement(Pattern.regexI("(<name>)"), StringReplacements.DELETE);
Function<String, String> replacer = builder.buildStringReplacer();
String instr = _readResource("SearcherTestInput2.txt");
String have = replacer.apply(instr);
String want = instr.replaceAll("<name>","").replaceAll("<NAME>","");
Assert.assertEquals(want, have);
}

@Test
public void testReplaceFunc() throws Exception
{
Expand Down

0 comments on commit 59ee0d2

Please sign in to comment.