You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/02/12 07:03:48 UTC

[GitHub] zenfenan commented on a change in pull request #3286: NIFI-5988 Fixed validation issues on database and collection names.

zenfenan commented on a change in pull request #3286: NIFI-5988 Fixed validation issues on database and collection names.
URL: https://github.com/apache/nifi/pull/3286#discussion_r255824356
 
 

 ##########
 File path: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/util/DatabaseNameValidator.java
 ##########
 @@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.nifi.processors.mongodb.util;
+
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator class for MongoDB database names. It is derived from the more restrictive rules for
+ * database names on Windows to ensure that this works on all of our supported platforms. See this for more details:
+ *
+ * https://docs.mongodb.com/manual/reference/limits/#restrictions-on-db-names
+ */
+public class DatabaseNameValidator implements Validator {
+    private static final DatabaseNameValidator INSTANCE = new DatabaseNameValidator();
+    private static final Pattern STRICT_NAME_VALIDATOR = Pattern.compile("/[\\/\\\\. \\\"\\$\\*\\<\\>\\:\\|\\?]/");
+
+    private DatabaseNameValidator() {
+
+    }
+
+    @Override
+    public ValidationResult validate(String subject, String input, ValidationContext context) {
+        ValidationResult.Builder builder = new ValidationResult.Builder()
+            .subject(subject)
+            .input(input);
+        Matcher matcher = STRICT_NAME_VALIDATOR.matcher(input);
+        if (matcher.find()) {
+            builder
+                .valid(false)
+                .explanation("Found an illegal character in the name.");
+        } else if (input.length() > 64) {
 
 Review comment:
   Should be `>= 64` since the database name should be fewer than 64 characters

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services