[ https://issues.apache.org/jira/browse/GEODE-1617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15667885#comment-15667885 ]
ASF GitHub Bot commented on GEODE-1617: --------------------------------------- Github user kjduling commented on a diff in the pull request: https://github.com/apache/incubator-geode/pull/285#discussion_r88081170 --- Diff: geode-core/src/test/java/org/apache/geode/cache/RegionNameValidationJUnitTest.java --- @@ -0,0 +1,75 @@ +package org.apache.geode.cache; + +import static org.junit.Assert.fail; + +import org.apache.geode.internal.cache.InternalRegionArguments; +import org.apache.geode.internal.cache.LocalRegion; +import org.apache.geode.test.junit.categories.UnitTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Category(UnitTest.class) +public class RegionNameValidationJUnitTest { + private static final Pattern NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_.]+"); + private static final String REGION_NAME = "MyRegion"; + + + @Test + public void testInvalidNames() { + InternalRegionArguments ira = new InternalRegionArguments(); + ira.setInternalRegion(false); + try { + LocalRegion.validateRegionName(null, ira); + fail(); + } catch (IllegalArgumentException ignore) { + } + try { + LocalRegion.validateRegionName("", ira); + fail(); + } catch (IllegalArgumentException ignore) { + } + try { + LocalRegion.validateRegionName("FOO" + Region.SEPARATOR, ira); + fail(); + } catch (IllegalArgumentException ignore) { + } + + } + + @Test + public void testExternalRegionNames() { + InternalRegionArguments ira = new InternalRegionArguments(); + ira.setInternalRegion(false); + validateCharacters(ira); + try { + LocalRegion.validateRegionName("__InvalidInternalRegionName", ira); + } catch (IllegalArgumentException ignore) { + } + } + + @Test + public void testInternalRegionNames() { + InternalRegionArguments ira = new InternalRegionArguments(); + ira.setInternalRegion(true); + LocalRegion.validateRegionName("__ValidInternalRegionName", ira); + } + + private void validateCharacters(InternalRegionArguments ira) { + for (int x = 0; x < Character.MAX_VALUE; x++) { + String name = (char) x + REGION_NAME; + Matcher matcher = NAME_PATTERN.matcher(name); + if (matcher.matches()) { + LocalRegion.validateRegionName(name, ira); + } else { + try { + LocalRegion.validateRegionName(name, ira); + fail("Should have received an IllegalArgumentException"); --- End diff -- I added printing the offending character and the numeric value of it. > Regions can be created with a variety of characters that are unsupported > ------------------------------------------------------------------------ > > Key: GEODE-1617 > URL: https://issues.apache.org/jira/browse/GEODE-1617 > Project: Geode > Issue Type: Bug > Components: gfsh > Affects Versions: 1.0.0-incubating.M2 > Reporter: Kevin Duling > Assignee: Kevin Duling > Fix For: 1.0.0-incubating > > > Per this > [thread|https://www.mail-archive.com/dev@geode.incubator.apache.org/msg04046.html], > and this > [thread|https://www.mail-archive.com/dev@geode.incubator.apache.org/msg07079.html] > on the dev forums and [geode > documentation|http://docs-geode-develop.cfapps.io/docs/basic_config/data_regions/region_naming.html], > region names may only consist of alphanumeric characters, an underscore, and > a hyphen. These rules are not enforced. > E.g., it is possible to create a region with: > {{gfsh> create region --name=not^good --type=REPLICATE}} > Some of these regions may be removed with the {{destroy}} command, while > others cannot be located. -- This message was sent by Atlassian JIRA (v6.3.4#6332)