sqlite-jdbc
sqlite-jdbc copied to clipboard
Fix possible StringIndexOutOfBoundsException
This PR proposes a fix for #1141 .
do you think you could add a test covering this ?
@gotson Really sorry for missing your comment. I have added in the unit test for the removeQuotation method.
@gotson Really sorry for missing your comment. I have added in the unit test for the removeQuotation method.
the test code doesn't compile
i've refactored your test code:
@ParameterizedTest
@MethodSource
public void removeQuotation(String input, String expected) throws SQLException {
assertThat(ExtendedCommand.removeQuotation(input)).isEqualTo(expected);
}
private static Stream<Arguments> removeQuotation() {
return Stream.of(
Arguments.of(null, null), // Null String
Arguments.of("'", "'"), // String with one single quotation only
Arguments.of("\"", "\""), // String with one double quotation only
Arguments.of("'Test\"", "'Test\""), // String with two mismatch quotations
Arguments.of("'Test'", "Test"), // String with two matching single quotations
Arguments.of("\"Test\"", "Test"), // String with two matching double quotations
Arguments.of("'Te's\"t'", "Te's\"t") // String with more than two quotations
);
}
@gotson, I have changed the parameter name but forget to push in the new one. Sorry for my careless mistake. And thanks for helping me to fix it.