Skip to content

Commit a63fa1d

Browse files
authored
Merge pull request #227 from TAMULib/fw_registry-issue_316-simple_sql_escape
FW Registry Issue 316: Add simple SQL sanitization.
2 parents 8874223 + 134431c commit a63fa1d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/main/java/org/folio/rest/utility/FormatUtility.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ private FormatUtility() {
1919

2020
}
2121

22+
/**
23+
* Perform basic SQL sanitization.
24+
*
25+
* Only the most basic forms of sanitization is performed.
26+
*
27+
* Single quotes are escaped using the standard method.
28+
* The Backslash Escape Sequence SQL feature is currently not supported.
29+
*
30+
* @param text The text to sanitize.
31+
* @return The sanitized text for use in SQL queries.
32+
*/
33+
public static String sanitizeSqlCode(String text) {
34+
if (text == null) {
35+
return text;
36+
}
37+
38+
return text.replace("'", "''");
39+
}
40+
2241
/**
2342
* Escape the text to ensure it can be safely used in CQL.
2443
*
@@ -34,7 +53,7 @@ private FormatUtility() {
3453
* @param text The text to normalize.
3554
* @return The normalized text for use inside the CQL as a value.
3655
*
37-
* @see https://github.com/folio-org/raml-module-builder/blob/2c39990c96c22262b02c98dd2b51cbeedc90fb9d/util/src/main/java/org/folio/util/StringUtil.java#L39
56+
* @see "https://github.com/folio-org/raml-module-builder/blob/2c39990c96c22262b02c98dd2b51cbeedc90fb9d/util/src/main/java/org/folio/util/StringUtil.java#L39"
3857
*/
3958
public static String normalizeCqlUrlArgument(String text) {
4059
if (text == null) {

0 commit comments

Comments
 (0)