Skip to content

Commit 387492a

Browse files
kno-trackunitravn-sorenNiels Wittrup AndersenJesper Rossen
authored
🔀 Fix/allow capital 'z' in search value (#6)
* Update README.md To reflect the actual implementation regarding Sort. * Allow more charecters in select values * Added wildcards to select * Added test of wildcards * Changed logic in Elements to support single element size spans * Expanded test with now valid input * Simplified logic in getElement * Allow more charecters in select values * Allow more charecters in select values * Added test of wildcards * Changed logic in Elements to support single element size spans * Expanded test with now valid input * Simplified logic in getElement * Changed logic in Elements to support single element size spans * Simplified logic in getElement * Adjusted elements logic to allow same start and end, or only one element * Removed duplicated test * Added test for single element equal to 0 * Suspicious character sequences now work as intended * Character sequences are unnessesary as they all start with '\' and '\' is on its own already not allowed * Reverted changes * Update Sanitizer.java * Update Sanitizer.java * PR requested changes Co-authored-by: Søren Ravn <[email protected]> Co-authored-by: Niels Wittrup Andersen <[email protected]> Co-authored-by: Jesper Rossen <[email protected]>
1 parent 48e7893 commit 387492a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/main/java/io/openapitools/api/capabilities/Sanitizer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* API input sanitizer in a rudimental version.
77
*/
88
public final class Sanitizer {
9-
private static final String[] SUSPICIOUS_CONTENT = {"\'", "\"", "\\", "%", "\\%", "\\_", "\0", "\b", "\n", "\t", "\r", "\\Z", "?", "#"};
9+
private static final char[] SUSPICIOUS_CONTENT = {'\'', '\"', '\\', '%', '\0', '\b', '\n', '\t', '\r', '?', '#'};
1010

1111
private Sanitizer() {
1212
// reduce scope to avoid default construction
@@ -18,7 +18,7 @@ private Sanitizer() {
1818
* @return String.
1919
*/
2020
static String regexQuotedSuspiciousContent() {
21-
return Pattern.quote(String.join("", SUSPICIOUS_CONTENT));
21+
return Pattern.quote(new StringBuilder().append(SUSPICIOUS_CONTENT).toString());
2222
}
2323

2424
/**
@@ -41,8 +41,8 @@ public static String sanitize(String input, boolean allowSpaces, boolean allowNu
4141
if (!allowNumbers) {
4242
result = result.matches(".*\\d.*") ? "" : result;
4343
}
44-
for (String s : SUSPICIOUS_CONTENT) {
45-
if (result.contains(s)) {
44+
for (char c: SUSPICIOUS_CONTENT) {
45+
if (result.contains(new Character(c).toString())) {
4646
return "";
4747
}
4848
}

src/test/java/io/openapitools/api/capabilities/SanitizerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ public void testSuspiciousInput() {
5959
assertEquals("", Sanitizer.sanitize("This is not ok input 2 '", true));
6060
assertEquals("", Sanitizer.sanitize("This is not ok input 2 'OR 1", true));
6161
}
62+
63+
@Test
64+
public void testCharSequence() {
65+
assertEquals("", Sanitizer.sanitize("this is not okay \\%",true));
66+
assertEquals("", Sanitizer.sanitize("this is not okay \\_",true));
67+
assertEquals("", Sanitizer.sanitize("this is \\Z not okay ",true));
68+
assertEquals("", Sanitizer.sanitize("this is not okay \\Z",true));
69+
70+
assertEquals("this is okay Z", Sanitizer.sanitize("this is okay Z",true));
71+
assertEquals("this is _ okay ", Sanitizer.sanitize("this is _ okay ",true));
72+
}
6273
}

src/test/java/io/openapitools/api/capabilities/SelectTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,10 @@ public void testWildcards() {
184184
assertTrue(sel.getValue().equals("*loan") || sel.getValue().equals("savings*"));
185185
}
186186
}
187+
188+
@Test
189+
public void testZ(){
190+
assertEquals(1,Select.getSelections("name::asdZ").size());
191+
assertEquals(0,Select.getSelections("name::asd\\Z").size());
192+
}
187193
}

0 commit comments

Comments
 (0)