Skip to content

Commit

Permalink
Fixed issue #3340
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jan 7, 2015
1 parent 0f6b773 commit 413f3de
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
Expand Up @@ -19,8 +19,6 @@
*/
package com.orientechnologies.orient.core.index;

import java.util.*;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.listener.OProgressListener;
import com.orientechnologies.common.log.OLogManager;
Expand All @@ -42,6 +40,15 @@
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Manages indexes at database level. A single instance is shared among multiple databases. Contentions are managed by r/w locks.
*
Expand Down Expand Up @@ -116,7 +123,7 @@ public OIndex<?> createIndex(final String iName, final String iType, final OInde
if (getDatabase().getTransaction().isActive())
throw new IllegalStateException("Cannot create a new index inside a transaction");

final Character c = OSchemaShared.checkNameIfValid(iName);
final Character c = OSchemaShared.checkClassNameIfValid(iName);
if (c != null)
throw new IllegalArgumentException("Invalid index name '" + iName + "'. Character '" + c + "' is invalid");

Expand Down
Expand Up @@ -1342,7 +1342,7 @@ public OPropertyImpl addPropertyInternal(final String name, final OType type, fi
if (name == null || name.length() == 0)
throw new OSchemaException("Found property name null");

final Character wrongCharacter = OSchemaShared.checkNameIfValid(name);
final Character wrongCharacter = OSchemaShared.checkFieldNameIfValid(name);
if (wrongCharacter != null)
throw new OSchemaException("Invalid property name found. Character '" + wrongCharacter + "' cannot be used in property name");

Expand Down
Expand Up @@ -105,7 +105,7 @@ public OSchemaShared(boolean clustersCanNotBeSharedAmongClasses) {
this.clustersCanNotBeSharedAmongClasses = clustersCanNotBeSharedAmongClasses;
}

public static Character checkNameIfValid(String iName) {
public static Character checkClassNameIfValid(String iName) {
if (iName == null)
throw new IllegalArgumentException("Name is null");

Expand All @@ -126,6 +126,27 @@ public static Character checkNameIfValid(String iName) {
return null;
}

public static Character checkFieldNameIfValid(String iName) {
if (iName == null)
throw new IllegalArgumentException("Name is null");

iName = iName.trim();

final int nameSize = iName.length();

if (nameSize == 0)
throw new IllegalArgumentException("Name is empty");

for (int i = 0; i < nameSize; ++i) {
final char c = iName.charAt(i);
if (c == ':' || c == ',' || c == ' ' || c == '%')
// INVALID CHARACTER
return c;
}

return null;
}

public boolean isFullCheckpointOnChange() {
return fullCheckpointOnChange;
}
Expand Down Expand Up @@ -329,7 +350,7 @@ public OClass createAbstractClass(final String className, final OClass superClas
}

public OClass createClass(final String className, final OClass superClass, int[] clusterIds) {
final Character wrongCharacter = OSchemaShared.checkNameIfValid(className);
final Character wrongCharacter = OSchemaShared.checkClassNameIfValid(className);
if (wrongCharacter != null)
throw new OSchemaException("Invalid class name found. Character '" + wrongCharacter + "' cannot be used in class name");

Expand Down Expand Up @@ -952,7 +973,7 @@ private OClass createClassInternal(final String className, final OClass superCla
if (Character.isDigit(className.charAt(0)))
throw new OSchemaException("Found invalid class name. Cannot start with numbers");

final Character wrongCharacter = checkNameIfValid(className);
final Character wrongCharacter = checkClassNameIfValid(className);
if (wrongCharacter != null)
throw new OSchemaException("Found invalid class name. Character '" + wrongCharacter + "' cannot be used in class name.");

Expand Down
Expand Up @@ -2211,7 +2211,7 @@ protected void setup() {
}

protected String checkFieldName(final String iFieldName) {
final Character c = OSchemaShared.checkNameIfValid(iFieldName);
final Character c = OSchemaShared.checkFieldNameIfValid(iFieldName);
if (c != null)
throw new IllegalArgumentException("Invalid field name '" + iFieldName + "'. Character '" + c + "' is invalid");

Expand Down

0 comments on commit 413f3de

Please sign in to comment.