{"record":{"id":"3e754b61444ae7bf","repo":"apache/shenyu","slug":"the-uri-cannot-contain-whitespaces-current-value-value","errorCode":null,"errorMessage":"The URI cannot contain whitespaces. Current value: \" + value","messagePattern":"The URI cannot contain whitespaces\\. Current value: \" \\+ value","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/UriConditionValidator.java","lineNumber":40,"sourceCode":"import org.apache.shenyu.common.enums.OperatorEnum;\nimport org.springframework.web.util.pattern.PathPatternParser;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Objects;\nimport java.util.function.Consumer;\n\npublic class UriConditionValidator {\n\n    private static final Map<String, Consumer<String>> VALIDATOR_MAP = new HashMap<>();\n\n    static {\n        Consumer<String> commonPathValidator = value -> {\n            if (!value.startsWith(\"/\")) {\n                throw new IllegalArgumentException(\"The URI must start with '/'\");\n            }\n            if (StringUtils.containsAny(value, \" \", \"\\t\", \"\\n\")) {\n                throw new IllegalArgumentException(\n                        \"The URI cannot contain whitespaces. Current value: \" + value);\n            }\n        };\n        Consumer<String> blankPathValidator = value -> {\n            if (StringUtils.isNotBlank(value)) {\n                throw new IllegalArgumentException(\"The URI must be blank\");\n            }\n        };\n        VALIDATOR_MAP.put(OperatorEnum.PATH_PATTERN.getAlias(),\n                PathPatternParser.defaultInstance::parse);\n        VALIDATOR_MAP.put(OperatorEnum.REGEX.getAlias(), Pattern::compile);\n        VALIDATOR_MAP.put(OperatorEnum.EQ.getAlias(), commonPathValidator);\n        VALIDATOR_MAP.put(OperatorEnum.STARTS_WITH.getAlias(), commonPathValidator);\n        VALIDATOR_MAP.put(OperatorEnum.ENDS_WITH.getAlias(), commonPathValidator);\n        VALIDATOR_MAP.put(OperatorEnum.MATCH.getAlias(), commonPathValidator);\n        VALIDATOR_MAP.put(OperatorEnum.EXCLUDE.getAlias(), commonPathValidator);\n        VALIDATOR_MAP.put(OperatorEnum.CONTAINS.getAlias(), commonPathValidator);\n        VALIDATOR_MAP.put(OperatorEnum.IS_BLANK.getAlias(), blankPathValidator);","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/UriConditionValidator.java#L22-L58","documentation":"UriConditionValidator validates the value of a URI-based selector condition before it is parsed by the matching operator (EQ, CONTAINS, etc.). It rejects values that contain whitespace characters (space, tab, newline) because such values could never match a URI path and would silently produce broken condition matching. The check runs eagerly in the static VALIDATOR_MAP consumers when validate() is invoked.","triggerScenarios":"Calling UriConditionValidator.validate(operator, value) with an operator alias mapped to commonPathValidator (EQ, CONTAINS, STARTS_WITH-family routed there) and a value containing a space, tab, or newline — e.g. value \"/api/ hello\" or one pasted with a trailing newline.","commonSituations":"Copying a URI from documentation or a browser with trailing whitespace, hand-editing selector conditions in the dashboard with a stray space, or programmatically building conditions by concatenating strings without trimming.","solutions":["Trim the condition value before storing/calling validate: value.trim().","Remove any internal spaces from the URI path; URIs cannot contain raw whitespace.","URL-encode any legitimately special segment instead of embedding spaces.","Check for newline contamination from file/config reads (strip \\r\\n)."],"exampleFix":"// before\nUriConditionValidator.validate(\"eq\", \"/api/ order\");\n// after\nUriConditionValidator.validate(\"eq\", \"/api/order\"); // trimmed, no whitespace","handlingStrategy":"validation","validationCode":"if (value != null && value.matches(\".*[ \\\\t\\\\n\\\\r].*\")) { throw new IllegalArgumentException(\"URI condition value must not contain whitespace: \" + value); }","typeGuard":"boolean isValidUriCondition(String v) { return v != null && v.startsWith(\"/\") && !v.matches(\".*[ \\\\t\\\\n\\\\r].*\"); }","tryCatchPattern":"try { UriConditionValidator.validate(operator, value); } catch (IllegalArgumentException e) { log.warn(\"Invalid URI condition value: {}\", value); /* reject or trim */ }","preventionTips":["Always trim values read from the dashboard/API before validating.","Reject whitespace in condition value fields at the UI level.","Strip trailing newlines when importing conditions from files.","Treat URI paths as encoded strings; never embed raw spaces."],"tags":["validation","uri","whitespace"],"backgroundTag":"invalid-argument-value","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}