Skip to content

Commit

Permalink
Fix regex string generation when no length is specified (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
C0urante committed Jan 28, 2022
1 parent cabd44f commit c0d9e85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -1373,7 +1373,14 @@ private String generateString(Schema schema, Map propertiesProp) {

String result;
if (regexProp != null) {
result = generateRegexString(schema, regexProp, getLengthBounds(propertiesProp));
Object lengthProp = propertiesProp.get(LENGTH_PROP);
LengthBounds lengthBounds;
if (lengthProp == null) {
lengthBounds = new LengthBounds(0, Integer.MAX_VALUE);
} else {
lengthBounds = getLengthBounds(lengthProp);
}
result = generateRegexString(schema, regexProp, lengthBounds);
} else {
result = generateRandomString(getLengthBounds(propertiesProp).random());
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/test-schemas/stackoverflow.json
@@ -0,0 +1,17 @@
{
"type": "record",
"name": "outer_doll",
"namespace": "io.confluent.avro.random.generator",
"fields": [
{
"name": "MY_STRING",
"type": {
"type": "string",
"arg.properties": {
"regex": "[a-zA-Z0-9]{16}"
}
},
"default": ""
}
]
}

0 comments on commit c0d9e85

Please sign in to comment.