Skip to content

[BUG] Resolve TODO: Add URI validation for other operators in Rule configuration #6334

@hengyuss

Description

@hengyuss

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Description

I found a // todo comment in the source code regarding the URI validation of RuleConditionDTO.

Currently, the createOrUpdate method in org/apache/shenyu/admin/service/RuleService.java only validates the URI format when the operator is PATH_PATTERN, and leaves a TODO for other matching modes:

// now, only check rule uri condition in pathPattern mode
// todo check uri in other modes

I propose to resolve this TODO by implementing strict validations for the remaining operators.

My plan is to introduce a UriConditionValidator using the Strategy Pattern to map different operators (regex, =, startsWith, endsWith) to their specific validation logic. This will make the validation robust and keep the main flow clean.

I am working on this and will submit a Pull Request shortly.

Expected Behavior

When the URI does not conform to the rules, it should throw an error instead of saving to the database.

Steps To Reproduce

  1. Go to ShenYu Admin Console -> Plugin List -> Add a Rule.
  2. Add a condition: ParamType uri, Operator regex.
  3. Input an invalid regex value, for example: [a-z+
  4. Click Save.
  5. Observe: The rule is saved successfully without any error prompt.
  6. Send a request to the Gateway matching this plugin.
  7. Observe: Gateway throws java.util.regex.PatternSyntaxException.

Environment

ShenYu version(s):2.7.1-SNAPSHOT

Debug logs

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions