mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 12:00:04 +02:00
GP-5159 - Fixed a bug when entering regex characters into a tree filter
field
This commit is contained in:
parent
97aadfa05a
commit
2f5416ab45
2 changed files with 33 additions and 11 deletions
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -57,7 +57,8 @@ public class UserSearchUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsWithPatternWithOnlyWildCardCaseInsensitive() {
|
public void testContainsWithPatternWithOnlyWildCardCaseInsensitive() {
|
||||||
Pattern pattern = UserSearchUtils.createContainsPattern("*", true, Pattern.CASE_INSENSITIVE);
|
Pattern pattern =
|
||||||
|
UserSearchUtils.createContainsPattern("*", true, Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
assertTrue(pattern.matcher("bb").matches());
|
assertTrue(pattern.matcher("bb").matches());
|
||||||
assertTrue(pattern.matcher("boxb").matches());
|
assertTrue(pattern.matcher("boxb").matches());
|
||||||
|
@ -77,6 +78,7 @@ public class UserSearchUtilsTest {
|
||||||
assertTrue(pattern.matcher("xbob").matches());
|
assertTrue(pattern.matcher("xbob").matches());
|
||||||
assertTrue(pattern.matcher("xxbobxx").matches());
|
assertTrue(pattern.matcher("xxbobxx").matches());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateContainsPatternWithSingleCharhWildCard() {
|
public void testCreateContainsPatternWithSingleCharhWildCard() {
|
||||||
Pattern pattern = UserSearchUtils.createContainsPattern("b?b", true, CASE_SENSITIVE);
|
Pattern pattern = UserSearchUtils.createContainsPattern("b?b", true, CASE_SENSITIVE);
|
||||||
|
@ -117,7 +119,7 @@ public class UserSearchUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateContainsPatternWildCardAtEnd() {
|
public void testCreateContainsPatternWildCardAtEnd() {
|
||||||
Pattern pattern = UserSearchUtils.createContainsPattern("*bob", true, CASE_SENSITIVE);
|
Pattern pattern = UserSearchUtils.createContainsPattern("bob*", true, CASE_SENSITIVE);
|
||||||
|
|
||||||
assertFalse(pattern.matcher("b").matches());
|
assertFalse(pattern.matcher("b").matches());
|
||||||
assertFalse(pattern.matcher("bb").matches());
|
assertFalse(pattern.matcher("bb").matches());
|
||||||
|
@ -129,7 +131,24 @@ public class UserSearchUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartsPatternNoWildCards() {
|
public void testCreateContainsPattern_NoWildcard_EscapedRegexCharacter() {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This is a regression test for a bug that was found when the user typed an escaped regex
|
||||||
|
// character into the search string. The utils will escape regex characters, so there is no
|
||||||
|
// need to do this unless you need to find a literal string containing "\["
|
||||||
|
//
|
||||||
|
|
||||||
|
Pattern pattern = UserSearchUtils.createContainsPattern("\\[bob", true, CASE_SENSITIVE);
|
||||||
|
|
||||||
|
assertFalse(pattern.matcher("b").matches());
|
||||||
|
assertFalse(pattern.matcher("bb").matches());
|
||||||
|
assertTrue(pattern.matcher("\\[bob").matches());
|
||||||
|
assertTrue(pattern.matcher("foo\\[bob").matches());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartsPatternNoWildCards() {
|
||||||
Pattern pattern = UserSearchUtils.createStartsWithPattern("bob", true, CASE_SENSITIVE);
|
Pattern pattern = UserSearchUtils.createStartsWithPattern("bob", true, CASE_SENSITIVE);
|
||||||
|
|
||||||
assertFalse(pattern.matcher("bb").matches());
|
assertFalse(pattern.matcher("bb").matches());
|
||||||
|
@ -140,7 +159,7 @@ public class UserSearchUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartsPatternNoWildCardsCaseSensitive() {
|
public void testStartsPatternNoWildCardsCaseSensitive() {
|
||||||
Pattern pattern = UserSearchUtils.createStartsWithPattern("boB", true, CASE_SENSITIVE);
|
Pattern pattern = UserSearchUtils.createStartsWithPattern("boB", true, CASE_SENSITIVE);
|
||||||
|
|
||||||
assertFalse(pattern.matcher("bb").matches());
|
assertFalse(pattern.matcher("bb").matches());
|
||||||
|
@ -155,7 +174,8 @@ public class UserSearchUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateStartsWithPatternWithOnlyWildCardCaseInsensitive() {
|
public void testCreateStartsWithPatternWithOnlyWildCardCaseInsensitive() {
|
||||||
Pattern pattern = UserSearchUtils.createStartsWithPattern("*", true, Pattern.CASE_INSENSITIVE);
|
Pattern pattern =
|
||||||
|
UserSearchUtils.createStartsWithPattern("*", true, Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
assertTrue(pattern.matcher("bb").matches());
|
assertTrue(pattern.matcher("bb").matches());
|
||||||
assertTrue(pattern.matcher("boxb").matches());
|
assertTrue(pattern.matcher("boxb").matches());
|
||||||
|
@ -163,6 +183,7 @@ public class UserSearchUtilsTest {
|
||||||
assertTrue(pattern.matcher("xbob").matches());
|
assertTrue(pattern.matcher("xbob").matches());
|
||||||
assertTrue(pattern.matcher("xxbobxx").matches());
|
assertTrue(pattern.matcher("xxbobxx").matches());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateStartsWithPatternWithOnlyWildCardCaseSensitive() {
|
public void testCreateStartsWithPatternWithOnlyWildCardCaseSensitive() {
|
||||||
// Note: case sensitivity should not matter
|
// Note: case sensitivity should not matter
|
||||||
|
@ -174,7 +195,7 @@ public class UserSearchUtilsTest {
|
||||||
assertTrue(pattern.matcher("xbob").matches());
|
assertTrue(pattern.matcher("xbob").matches());
|
||||||
assertTrue(pattern.matcher("xxbobxx").matches());
|
assertTrue(pattern.matcher("xxbobxx").matches());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateStartsWithPatternWithSingleCharhWildCard() {
|
public void testCreateStartsWithPatternWithSingleCharhWildCard() {
|
||||||
Pattern pattern = UserSearchUtils.createStartsWithPattern("b?b", true, CASE_SENSITIVE);
|
Pattern pattern = UserSearchUtils.createStartsWithPattern("b?b", true, CASE_SENSITIVE);
|
||||||
|
@ -449,7 +470,8 @@ public class UserSearchUtilsTest {
|
||||||
public void testEscapeSomeRegexCharacters() {
|
public void testEscapeSomeRegexCharacters() {
|
||||||
// RegEx Special Chars: ^.$()[]+&{}*?
|
// RegEx Special Chars: ^.$()[]+&{}*?
|
||||||
char[] toIgnore = { '(', ')' };
|
char[] toIgnore = { '(', ')' };
|
||||||
String escaped = UserSearchUtils.escapeSomeRegexCharacters("start^.$()[]+&{}*?end", toIgnore);
|
String escaped =
|
||||||
|
UserSearchUtils.escapeSomeRegexCharacters("start^.$()[]+&{}*?end", toIgnore);
|
||||||
|
|
||||||
assertEquals("start\\^\\.\\$()\\[\\]\\+\\&\\{\\}\\*\\?end", escaped);
|
assertEquals("start\\^\\.\\$()\\[\\]\\+\\&\\{\\}\\*\\?end", escaped);
|
||||||
|
|
||||||
|
|
|
@ -309,8 +309,8 @@ public class UserSearchUtils {
|
||||||
if (allowGlobbing) {
|
if (allowGlobbing) {
|
||||||
|
|
||||||
// Note: Order is important! (due to how escape characters added and checked)
|
// Note: Order is important! (due to how escape characters added and checked)
|
||||||
escaped = escapeEscapeCharacters(input);
|
escaped = escapeEscapeCharacters(escaped);
|
||||||
escaped = escapeNonGlobbingRegexCharacters(input);
|
escaped = escapeNonGlobbingRegexCharacters(escaped);
|
||||||
escaped = convertGlobbingCharactersToRegex(escaped);
|
escaped = convertGlobbingCharactersToRegex(escaped);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue