diff --git hplsql/src/main/java/org/apache/hive/hplsql/Utils.java hplsql/src/main/java/org/apache/hive/hplsql/Utils.java index d261df1..e9174ef 100644 --- hplsql/src/main/java/org/apache/hive/hplsql/Utils.java +++ hplsql/src/main/java/org/apache/hive/hplsql/Utils.java @@ -27,27 +27,29 @@ * Unquote string and remove escape characters inside the script */ public static String unquoteString(String s) { - if(s == null) { + if (s == null) { return null; - } - + } + int i = 0; int len = s.length(); - StringBuilder s2 = new StringBuilder(len); - - for (int i = 0; i < len; i++) { - char ch = s.charAt(i); - char ch2 = (i < len - 1) ? s.charAt(i+1) : 0; - - if((i == 0 || i == len -1) && (ch == '\'' || ch == '"')) + StringBuffer s2 = new StringBuffer(len); + while (i < len) { + char ch = s.charAt(i); + char ch2 = (i < len - 1) ? s.charAt(i + 1) : 0; + if ((i == 0 || i == len - 1) && (ch == '\'' || ch == '"')) { + i++; continue; + } else // \' and '' escape sequences - if((ch == '\\' && ch2 == '\'') || (ch == '\'' && ch2 == '\'')) + if ((ch == '\\' && ch2 == '\'') || (ch == '\'' && ch2 == '\'')) { + s2.append(ch2); + i += 2; continue; - + } s2.append(ch); - } - + i++; + } return s2.toString(); } diff --git hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlLocal.java hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlLocal.java index 8692661..100b432 100644 --- hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlLocal.java +++ hplsql/src/test/java/org/apache/hive/hplsql/TestHplsqlLocal.java @@ -298,6 +298,11 @@ public void testPrint() throws Exception { } @Test + public void testQuotes2() throws Exception { + run("quotes2"); + } + + @Test public void testReplace() throws Exception { run("replace"); } diff --git hplsql/src/test/queries/local/quotes2.sql hplsql/src/test/queries/local/quotes2.sql new file mode 100644 index 0000000..3ace7b3 --- /dev/null +++ hplsql/src/test/queries/local/quotes2.sql @@ -0,0 +1,4 @@ +PRINT ''' '; +PRINT ''''; +PRINT ''' ' || 'end'; +PRINT '''' || 'end'; \ No newline at end of file diff --git hplsql/src/test/results/local/quotes2.out.txt hplsql/src/test/results/local/quotes2.out.txt new file mode 100644 index 0000000..ee1684b --- /dev/null +++ hplsql/src/test/results/local/quotes2.out.txt @@ -0,0 +1,8 @@ +Ln:1 PRINT +' +Ln:2 PRINT +' +Ln:3 PRINT +' end +Ln:4 PRINT +'end \ No newline at end of file