Skip to content

Commit 2ce7f7a

Browse files
1 parent 5fa2a7a commit 2ce7f7a

5 files changed

Lines changed: 97 additions & 28 deletions

File tree

commons/src/main/java/com/orientechnologies/common/parser/OBaseParser.java

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ protected void parserNextWord(final boolean iForceUpperCase) {
327327
/**
328328
* Parses the next word.
329329
*
330-
* @param iUpperCase
330+
* @param iForceUpperCase
331331
* True if must return UPPERCASE, otherwise false
332-
* @param iSeparators
332+
* @param iSeparatorChars
333333
* Separator characters
334334
*/
335335
protected void parserNextWord(final boolean iForceUpperCase, final String iSeparatorChars) {
@@ -362,69 +362,78 @@ protected void parserNextWord(final boolean iForceUpperCase, final String iSepar
362362

363363
try {
364364
int openParenthesis = 0;
365-
int openBraket = 0;
365+
int openBracket = 0;
366366
int openGraph = 0;
367-
boolean escape = false;
367+
368+
int escapePos = -1;
368369

369370
for (; parserCurrentPos < text2Use.length(); parserCurrentPos++) {
370371
final char c = text2Use.charAt(parserCurrentPos);
371372

372-
if (!escape && c == '\\' && ((parserCurrentPos + 1) < text2Use.length())) {
373+
if (c == '\\' && ((parserCurrentPos + 1) < text2Use.length())) {
373374
// ESCAPE CHARS
374-
final char nextChar = text2Use.charAt(parserCurrentPos + 1);
375-
376-
if (nextChar == 'u') {
377-
parserCurrentPos = OStringParser.readUnicode(text2Use, parserCurrentPos + 2, parserLastWord);
378-
} else {
379-
// parserLastWord.append(c);
380-
parserLastWord.append(nextChar);
381-
parserCurrentPos++;
382-
}
383375

384-
continue;
376+
if (openGraph == 0) {
377+
final char nextChar = text2Use.charAt(parserCurrentPos + 1);
378+
379+
if (nextChar == 'u') {
380+
parserCurrentPos = OStringParser.readUnicode(text2Use, parserCurrentPos + 2, parserLastWord);
381+
} else {
382+
parserLastWord.append(nextChar);
383+
parserCurrentPos++;
384+
}
385+
386+
continue;
387+
} else
388+
escapePos = parserCurrentPos;
385389
}
386390

387-
if (openBraket == 0 && openGraph == 0 && openParenthesis == 0 && !escape && (c == '\'' || c == '"')) {
391+
if (escapePos == -1 && (c == '\'' || c == '"')) {
388392
if (stringBeginChar != ' ') {
389393
// CLOSE THE STRING?
390394
if (stringBeginChar == c) {
391395
// SAME CHAR AS THE BEGIN OF THE STRING: CLOSE IT AND PUSH
392396
stringBeginChar = ' ';
393-
parserLastWord.append(c);
394-
parserCurrentPos++;
395-
break;
397+
398+
if (openBracket == 0 && openGraph == 0 && openParenthesis == 0) {
399+
parserCurrentPos++;
400+
parserLastWord.append(c);
401+
break;
402+
}
396403
}
397404
} else
398405
// START STRING
399406
stringBeginChar = c;
400-
} else if (stringBeginChar == ' ') {
401-
if (openBraket == 0 && openGraph == 0 && openParenthesis == 0 && parserCheckSeparator(c, iSeparatorChars)) {
407+
}
408+
409+
if (stringBeginChar == ' ') {
410+
if (openBracket == 0 && openGraph == 0 && openParenthesis == 0 && parserCheckSeparator(c, iSeparatorChars)) {
402411
// SEPARATOR FOUND!
403412
break;
404413
} else if (c == '(')
405414
openParenthesis++;
406415
else if (c == ')' && openParenthesis > 0)
407416
openParenthesis--;
408417
else if (c == '[')
409-
openBraket++;
410-
else if (c == ']' && openBraket > 0)
411-
openBraket--;
418+
openBracket++;
419+
else if (c == ']' && openBracket > 0)
420+
openBracket--;
412421
else if (c == '{')
413422
openGraph++;
414423
else if (c == '}' && openGraph > 0)
415424
openGraph--;
416425
}
417426

418-
parserLastWord.append(c);
427+
if (escapePos != parserCurrentPos)
428+
escapePos = -1;
419429

420-
if (escape)
421-
escape = false;
430+
parserLastWord.append(c);
422431
}
423432

424433
// CHECK MISSING CHARACTER
425434
if (stringBeginChar != ' ')
426435
throw new IllegalStateException("Missing closed string character: '" + stringBeginChar + "', position: " + parserCurrentPos);
427-
if (openBraket > 0)
436+
if (openBracket > 0)
428437
throw new IllegalStateException("Missing closed braket character: ']', position: " + parserCurrentPos);
429438
if (openGraph > 0)
430439
throw new IllegalStateException("Missing closed graph character: '}', position: " + parserCurrentPos);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.orientechnologies.orient.test.database.auto;
2+
3+
import com.orientechnologies.orient.core.metadata.schema.OClass;
4+
import com.orientechnologies.orient.core.metadata.schema.OSchema;
5+
import com.orientechnologies.orient.core.metadata.schema.OType;
6+
import com.orientechnologies.orient.core.record.impl.ODocument;
7+
import com.orientechnologies.orient.core.sql.OCommandSQL;
8+
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
9+
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
10+
import org.testng.Assert;
11+
import org.testng.annotations.Optional;
12+
import org.testng.annotations.Parameters;
13+
import org.testng.annotations.Test;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
/**
19+
* @author Andrey Lomakin <a href="mailto:[email protected]">Andrey Lomakin</a>
20+
* @since 3/24/14
21+
*/
22+
@Test
23+
public class SQLCreateVertexTest extends BaseTest {
24+
25+
@Parameters(value = "url")
26+
public SQLCreateVertexTest(@Optional String url) {
27+
super(url);
28+
}
29+
30+
public void testCreateVertexByContent() {
31+
OrientGraph graph = new OrientGraph(database, false);
32+
graph.shutdown();
33+
database.open("admin", "admin");
34+
35+
OSchema schema = database.getMetadata().getSchema();
36+
if (!schema.existsClass("CreateVertexByContent")) {
37+
OClass vClass = schema.createClass("CreateVertexByContent", schema.getClass("V"));
38+
vClass.createProperty("message", OType.STRING);
39+
}
40+
41+
database.command(new OCommandSQL("create vertex CreateVertexByContent content { \"message\": \"(:\"}")).execute();
42+
database.command(new OCommandSQL("create vertex CreateVertexByContent content { \"message\": \"\\\"‎ה, כן?...‎\\\"\"}")).execute();
43+
44+
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from CreateVertexByContent"));
45+
Assert.assertEquals(result.size(), 2);
46+
47+
List<String> messages = new ArrayList<String>();
48+
messages.add("\"‎ה, כן?...‎\"");
49+
messages.add("(:");
50+
51+
for (ODocument document : result) {
52+
Assert.assertTrue(messages.remove(document.<String>field("message")));
53+
}
54+
55+
Assert.assertEquals(messages.size(), 0);
56+
}
57+
}

tests/src/test/java/com/orientechnologies/orient/test/database/auto/memory-test-db-from-scratch.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<class name="com.orientechnologies.orient.test.database.auto.SQLFunctionsTest"/>
143143
<class name="com.orientechnologies.orient.test.database.auto.SQLUpdateTest"/>
144144
<class name="com.orientechnologies.orient.test.database.auto.SQLDeleteTest"/>
145+
<class name="com.orientechnologies.orient.test.database.auto.SQLCreateVertexTest"/>
145146
</classes>
146147
</test>
147148
<test name="other-commands">

tests/src/test/java/com/orientechnologies/orient/test/database/auto/paginated-local-test-db-from-scratch.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<class name="com.orientechnologies.orient.test.database.auto.SQLFunctionsTest"/>
153153
<class name="com.orientechnologies.orient.test.database.auto.SQLUpdateTest"/>
154154
<class name="com.orientechnologies.orient.test.database.auto.SQLDeleteTest"/>
155+
<class name="com.orientechnologies.orient.test.database.auto.SQLCreateVertexTest"/>
155156
</classes>
156157
</test>
157158
<test name="other-commands">

tests/src/test/java/com/orientechnologies/orient/test/database/auto/remote-test-db-from-scratch.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<!-- class name="com.orientechnologies.orient.test.database.auto.SQLFunctionsTest" / -->
134134
<class name="com.orientechnologies.orient.test.database.auto.SQLUpdateTest"/>
135135
<class name="com.orientechnologies.orient.test.database.auto.SQLDeleteTest"/>
136+
<class name="com.orientechnologies.orient.test.database.auto.SQLCreateVertexTest"/>
136137
</classes>
137138
</test>
138139
<test name="other-commands">

0 commit comments

Comments
 (0)