ASTERIXDB-1749: fix breaking of lines using '\r'
Change-Id: Ica5ce0b82f1d2c6f2033be2ce20bf56a563fb57b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1382
Reviewed-by: Michael Blow <mblow@apache.org>
Tested-by: Michael Blow <mblow@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/parser/ScopeChecker.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/parser/ScopeChecker.java
index 767eacb..1195d37 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/parser/ScopeChecker.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/parser/ScopeChecker.java
@@ -51,7 +51,7 @@
}
protected void setInput(String s) {
- inputLines = s.split("\n");
+ inputLines = s.split("\n|\r\n?");
}
// Forbidden scopes are used to disallow, in a limit clause, variables
diff --git a/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java b/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java
new file mode 100644
index 0000000..27679a9
--- /dev/null
+++ b/asterixdb/asterix-lang-sqlpp/src/test/java/org/apache/asterix/lang/sqlpp/parser/ParserTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.lang.sqlpp.parser;
+
+import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.lang.common.base.IParser;
+import org.apache.asterix.lang.common.base.IParserFactory;
+import org.junit.Test;
+
+public class ParserTest {
+
+ protected void testLineEnding(String query) throws Exception {
+ IParserFactory factory = new SqlppParserFactory();
+ IParser parser = factory.createParser(query);
+ try {
+ parser.parse();
+ } catch (AsterixException e) {
+ if (!e.getMessage().contains("Syntax error: In line 3")) {
+ throw new Exception("Unexpected error", e);
+ }
+ }
+ }
+
+ @Test
+ public void testCR() throws Exception {
+ testLineEnding("select\rvalue\r1");
+ }
+
+ @Test
+ public void testCRLF() throws Exception {
+ testLineEnding("select\r\nvalue\r\n1");
+ }
+
+ @Test
+ public void testLF() throws Exception {
+ testLineEnding("select\nvalue\n1");
+ }
+}