2 * ============LICENSE_START=======================================================
\r
3 * Copyright (C) 2019 Nordix Foundation.
\r
4 * ================================================================================
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
17 * SPDX-License-Identifier: Apache-2.0
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.onap.dmaap.datarouter.node;
\r
24 * FORTIFY SCAN FIXES.
\r
25 * <p>This Utility is used for Fortify fixes. It Validates the path url formed from
\r
26 * the string passed in the request parameters.</p>
\r
30 private PathUtil() {
\r
31 throw new IllegalStateException("Utility Class");
\r
35 * This method takes String as the parameter and return the filtered path string.
\r
37 * @param string String to clean
\r
38 * @return A cleaned String
\r
40 static String cleanString(String string) {
\r
41 if (string == null) {
\r
44 StringBuilder cleanString = new StringBuilder();
\r
45 for (int i = 0; i < string.length(); ++i) {
\r
46 cleanString.append(cleanChar(string.charAt(i)));
\r
48 return cleanString.toString();
\r
52 * This method filters the valid special characters in path string.
\r
54 * @param character The char to be cleaned
\r
55 * @return The cleaned char
\r
57 private static char cleanChar(char character) {
\r
59 for (int i = 48; i < 58; ++i) {
\r
60 if (character == i) {
\r
65 for (int i = 65; i < 91; ++i) {
\r
66 if (character == i) {
\r
71 for (int i = 97; i < 123; ++i) {
\r
72 if (character == i) {
\r
76 return getValidCharacter(character);
\r
79 private static char getValidCharacter(char character) {
\r
80 // other valid characters
\r
81 switch (character) {
\r