{"record":{"id":"5ec26b0f3033844c","repo":"apache/shenyu","slug":"the-uri-must-start-with","errorCode":null,"errorMessage":"The URI must start with '/'","messagePattern":"The URI must start with '/'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/UriConditionValidator.java","lineNumber":37,"sourceCode":"\nimport com.google.re2j.Pattern;\nimport org.apache.commons.lang3.StringUtils;\nimport 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);","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/validation/validator/UriConditionValidator.java#L19-L55","documentation":"UriConditionValidator validates URI-type condition parameter values on selector/rule conditions in shenyu-admin. Its commonPathValidator requires every URI value to start with '/' and throws IllegalArgumentException otherwise. This ensures condition values are valid path expressions for gateway matching.","triggerScenarios":"Saving a selector or rule with a URI condition whose value does not begin with '/', e.g. \"api/user\" or \"http://host/api\" instead of \"/api/user\"; the validator's static VALIDATOR_MAP consumer runs on the stored value.","commonSituations":"Typing relative or full-URL values into the dashboard's condition editor; scripted admin API calls that build condition values without the leading slash; copy-pasting backend URLs into path conditions.","solutions":["Prefix the value with '/': use \"/api/user\", not \"api/user\".","Strip scheme/host if a full URL was pasted — keep only the path portion.","Update automation/scripts to normalize path values before calling the admin API."],"exampleFix":"// before\ncondition.setParamValue(\"api/user\");\n// after\ncondition.setParamValue(\"/api/user\");","handlingStrategy":"validation","validationCode":"String normalizeUri(String value) {\n    if (value.startsWith(\"http://\") || value.startsWith(\"https://\")) {\n        value = URI.create(value).getPath();\n    }\n    if (!value.startsWith(\"/\")) { value = \"/\" + value; }\n    return value;\n}","typeGuard":"boolean isValidUriCondition(String value) {\n    return value != null && value.startsWith(\"/\") && !value.matches(\".*[ \\\\t\\\\n].*\");\n}","tryCatchPattern":"try {\n    conditionService.save(condition);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"must start with '/'\")) {\n        log.error(\"Fix condition URI: prefix value with '/'\");\n    }\n}","preventionTips":["Always express URI conditions as paths starting with '/'.","Strip scheme and host when pasting full URLs into condition editors.","Normalize path values in automation before calling the admin API."],"tags":["validation","uri","condition","admin-api"],"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"}