sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

Fix possible StringIndexOutOfBoundsException

Open arthurscchan opened this issue 1 year ago • 1 comments

This PR proposes a fix for #1141 .

arthurscchan avatar Aug 19 '24 19:08 arthurscchan

do you think you could add a test covering this ?

gotson avatar Aug 20 '24 01:08 gotson

@gotson Really sorry for missing your comment. I have added in the unit test for the removeQuotation method.

arthurscchan avatar Nov 19 '24 11:11 arthurscchan

@gotson Really sorry for missing your comment. I have added in the unit test for the removeQuotation method.

the test code doesn't compile

gotson avatar Nov 20 '24 03:11 gotson

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 avatar Nov 20 '24 03:11 gotson

@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.

arthurscchan avatar Nov 20 '24 10:11 arthurscchan