Skip to content

Commit

Permalink
fixed validation of name on setName and unsafe keyword parsing for al…
Browse files Browse the repository at this point in the history
…ter, issue #3791
  • Loading branch information
tglman committed Jul 6, 2015
1 parent 1a90447 commit 26f0f55
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
package com.orientechnologies.orient.core.metadata.schema;

import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.orientechnologies.common.listener.OProgressListener;
import com.orientechnologies.common.util.OArrays;
Expand Down Expand Up @@ -583,6 +593,10 @@ void removeSuperClassInternal(final OClass superClass) {

public OClass setName(final String name) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
final Character wrongCharacter = OSchemaShared.checkClassNameIfValid(name);
if (wrongCharacter != null)
throw new OSchemaException("Invalid class name found. Character '" + wrongCharacter + "' cannot be used in class name '"
+ name + "'");
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ public OCommandExecutorSQLAlterClass parse(final OCommandRequest iRequest) {

value = parserText.substring(pos + 1).trim();

if (parserTextUpperCase.endsWith("UNSAFE")) {
unsafe = true;
value = value.substring(0, value.length() - "UNSAFE".length());
for (int i = value.length() - 1; value.charAt(i) == ' ' || value.charAt(i) == '\t'; i--)
value = value.substring(0, value.length() - 1);
}
if (value.length() == 0)
throw new OCommandSQLParsingException("Missed the property's value to change for attribute '" + attribute + "'", parserText,
oldPos);

if (value.equalsIgnoreCase("null"))
value = null;

if (parserTextUpperCase.endsWith("UNSAFE"))
unsafe = true;

return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.orientechnologies.orient.core.sql;

import static org.testng.AssertJUnit.assertNotNull;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.OSchemaException;

public class SQLAlterClassTest {

@Test
public void alterClassRenameTest() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + SQLAlterClassTest.class.getName());
db.create();
try {
db.getMetadata().getSchema().createClass("TestClass");

try {
db.command(new OCommandSQL("alter class TestClass name = 'test_class'")).execute();
Assert.fail("the rename should fail for wrong syntax");
} catch (OSchemaException ex) {

}
assertNotNull(db.getMetadata().getSchema().getClass("TestClass"));

} finally {
db.drop();
}
}

}

0 comments on commit 26f0f55

Please sign in to comment.