shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

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

Open hengyuss opened this issue 7 months ago • 1 comments

Is there an existing issue for this?

  • [x] 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

hengyuss avatar Apr 24 '26 10:04 hengyuss

👋 Hello @yuluo-yx

A new issue has been opened by @hengyuss:

  • Title: [BUG] Resolve TODO: Add URI validation for other operators in Rule configuration
  • Link: https://github.com/apache/shenyu/issues/6334

Please review when you have time. Thank you! 🙏

github-actions[bot] avatar Apr 24 '26 10:04 github-actions[bot]