Skip to content

Commit

Permalink
Espaces curly brackets in sql script (with json).
Browse files Browse the repository at this point in the history
Closes #68
  • Loading branch information
manuelaznar authored and bartoszmajsak committed Apr 5, 2017
1 parent 760c625 commit d0996fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@
public class SpecialCharactersReplacer {

public String escape(String source) {
return source.replaceAll("(?m)&(.[a-zA-Z0-9]*);", "ape_special[$1]");
String result = source.replaceAll("(?m)&(.[a-zA-Z0-9]*);", "ape_special[$1]");
result = result.replace("\\{", "ape_especial_curly_brackets_begin");
result = result.replace("\\}", "ape_especial_curly_brackets_end");
return result;
}

public String unescape(String source) {
return source.replaceAll("(?m)ape_special\\[(.[a-zA-Z0-9]*)]", "&$1;");
String result = source.replaceAll("(?m)ape_special\\[(.[a-zA-Z0-9]*)]", "&$1;");
result = result.replace("ape_especial_curly_brackets_begin", "{");
result = result.replace("ape_especial_curly_brackets_end", "}");

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,19 @@ public void should_insert_xml_tags_new_line_as_statement_delimiter() throws Exce
" values (2, 'John', 'Sharp', 'asdqwe', 'closing only</strong>')"
);
}

@Test
public void should_insert_json_tags() throws Exception {
// given
ArgumentCaptor<String> statementsCaptor = ArgumentCaptor.forClass(String.class);

// when
scriptExecutor.execute(FileLoader.loadAsString("scripts/insert-with-json.sql"));

// then
verify(connection, times(1)).createStatement();
verify(connection.createStatement(), times(1)).execute(statementsCaptor.capture());
assertThat(statementsCaptor.getAllValues()).containsSequence(
"INSERT INTO `com` (`comtxt`) VALUES ('{}');");
}
}
1 change: 1 addition & 0 deletions core/src/test/resources/scripts/insert-with-json.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `com` (`comtxt`) VALUES ('\{\}');

0 comments on commit d0996fc

Please sign in to comment.