+++ /dev/null
-/*-\r
- * ============LICENSE_START=======================================================\r
- * Copyright (C) 2019 Nordix Foundation.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.dmaap.datarouter.node;\r
-\r
-/**\r
- * FORTIFY SCAN FIXES.\r
- * <p>This Utility is used for Fortify fixes. It Validates the path url formed from\r
- * the string passed in the request parameters.</p>\r
- */\r
-class PathUtil {\r
-\r
- private PathUtil() {\r
- throw new IllegalStateException("Utility Class");\r
- }\r
-\r
- /**\r
- * This method takes String as the parameter and return the filtered path string.\r
- *\r
- * @param string String to clean\r
- * @return A cleaned String\r
- */\r
- static String cleanString(String string) {\r
- if (string == null) {\r
- return null;\r
- }\r
- StringBuilder cleanString = new StringBuilder();\r
- for (int i = 0; i < string.length(); ++i) {\r
- cleanString.append(cleanChar(string.charAt(i)));\r
- }\r
- return cleanString.toString();\r
- }\r
-\r
- /**\r
- * This method filters the valid special characters in path string.\r
- *\r
- * @param character The char to be cleaned\r
- * @return The cleaned char\r
- */\r
- private static char cleanChar(char character) {\r
- // 0 - 9\r
- for (int i = 48; i < 58; ++i) {\r
- if (character == i) {\r
- return (char) i;\r
- }\r
- }\r
- // 'A' - 'Z'\r
- for (int i = 65; i < 91; ++i) {\r
- if (character == i) {\r
- return (char) i;\r
- }\r
- }\r
- // 'a' - 'z'\r
- for (int i = 97; i < 123; ++i) {\r
- if (character == i) {\r
- return (char) i;\r
- }\r
- }\r
- return getValidCharacter(character);\r
- }\r
-\r
- private static char getValidCharacter(char character) {\r
- // other valid characters\r
- switch (character) {\r
- case '/':\r
- return '/';\r
- case '.':\r
- return '.';\r
- case '-':\r
- return '-';\r
- case ':':\r
- return ':';\r
- case '?':\r
- return '?';\r
- case '&':\r
- return '&';\r
- case '=':\r
- return '=';\r
- case '#':\r
- return '#';\r
- case '_':\r
- return '_';\r
- case ' ':\r
- return ' ';\r
- default:\r
- return '%';\r
- }\r
- }\r
-}\r